Search this site:

2009-01-22

Globalization in Programing


The world is really that large, strange bugs often arise when a program goes global...

Recently I was prompted for a strange FormatException when a user from Europe test my program. It's was really strange the double.Parse("0.70") would throw such an exception. "What's wrong with this 0.70, isn't it a standard form of double? Is the problem caused by the tailing zero?" I wondered.

Certainly not. The .NET Framework shouldn't be that stupid not to be able to handle those trailing zeros. After some web search, I found the answer at here. Oh my god, the world is really that large, I don't know some countries like France use commas instead of periods for decimal points in numbers (i.e. "0,70" instead of "0.70")... The solution was also in that page, that I should tell the program not to use local culture when parsing parsing the number like this:

double.Parse(str, System.Globalization.CultureInfo.InvariantCulture);


Oops. I know that we can (and we should) supply a culture information to the Parse function whenever possible from the day I started using .NET Framwork. I am just too lazy to add it everytime. As I result I need to search for all ".Parse(" pattern in the pieces of code again to fix this problem. This story tell us again we should never be lazy when writing programes, espeically when it is up to certain scale... Same lesson learnt, again.


No comments:

Post a Comment

HTML Tags allowed (e.g. <b>, <i>, <a>)

Disclaimer

ALL CONTENTS AND INFORMATION IN THIS WEB SITE ARE PROVIDED "AS IT" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE ACCURACY AND AVAILABILITY OF THE CONTENTS, INFORMATION AND THE WEB SITE ITSELF ARE NOT GUARANTEED. THE AUTHOR TAKES NO RESPONSIBILITIES ON ANY COSTS OR DAMAGES (DIRECT OR INDIRECT) ARISING OUT OF OR IN CONNECTION WITH THE ACCESS, USAGE OR INABILITY OF USAGE OF THIS WEB SITE.