2

I have a question about how to handle culture while parsing doubles. In a system price information from various servers comes together. However the data thats given as input varies in culture. two million and fifty cents is given as :
"2.000.000,50"
"2,000,000.50"
"2000000.50"
"2000000,50"

is there a generic way to handle these various types of input ?

Shingala94
  • 404
  • 3
  • 18

2 Answers2

2

No, there is no generic way. You either need to know what culture the double was formatted or all the servers need to send in a single format, say InvariantCulture.

If you guess the culture, there's a bad news waiting for you as different cultures use different decimal separator, group separator etc. So you can't.

Refer this to foresee what can go wrong if you guess.

Community
  • 1
  • 1
Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
0

Please see https://stackoverflow.com/a/27443540/1230816 for an answer to your examples without any cultural assumptions required.

Community
  • 1
  • 1
Jemolah
  • 1,962
  • 3
  • 24
  • 41
  • While this link may answer the question, it is better to include the essential parts of the answer [here](http://meta.stackoverflow.com/a/8259) and provide the link for reference. Link-only answers can become invalid if the linked page changes. Links to SO are handled the same way. – bummi Dec 12 '14 at 14:31