How to handle culture in double parsing in C #?

I have a question about how to handle culture when parsing pairs. In the system price, information from different servers is combined. However, the data given as input differs by culture. two million and fifty cents are indicated as:
"2.000.000.50"
"2,000,000.50"
"2000000.50"
"2000000.50"

is there a general way to handle these different types of input?

+2


source to share


2 answers


No, there is no general way. You either need to know what culture was formatted double

, or all servers should send in the same format, for example InvariantCulture

.

If you guess the culture, bad news awaits you because different cultures use different decimal separator, group separator, etc. Therefore you cannot.



Refer to this to anticipate what might go wrong, if you guessed it.

+2


source


Refer to fooobar.com/questions/2184358 / ... for answers to your examples without any cultural assumptions.



0


source







All Articles