Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all again,

I have a desktop application. This application is all about computing numbers. But recently, I found a problem. In Greece, they have different number format from canada. For example, in canada, we use 1,000,000.00, but in Greece, they use 1.000.000,00. If my application read a file from Greece, it said "invalid formatting and cannot be read". I set
C#
thread.CurrentThread.CurrentCulture = new CultureInfo("el-GR");

in my application, it does not work for sure. How can I solve this problem from programming? I totally have no clue.
Thanks in advance.
Posted
Updated 20-Dec-11 11:16am
v3
Comments
Sergey Alexandrovich Kryukov 20-Dec-11 22:13pm    
This is not locale!
--SA

1 solution

If possible, numbers should be stored in a format that works across cultures. This can be done by storing them in binary so culture is irrelevant, or by storing them as text strings using a single known culture (preferably the Invariant culture). This way you always know how to read in the numbers from your file(s) and can use any other culture you want to display those numbers in your application.

Documentation for Decimal.ToString(IFormatProvider)[^] - Used to write a decimal value using a specific culture. Other numeric types and String.Format() have similar overloads using IFormatProvider.

Documentation for BinaryReader class[^] - Used to read in data from binary files.

Documentation for BinaryWriter class[^] - Used to write data to binary files.
 
Share this answer
 
Comments
Member 8256632 20-Dec-11 13:06pm    
Got it, thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900