How to convert “12,4” to decimal en-Us culture

前端 未结 7 2194
梦如初夏
梦如初夏 2020-12-16 02:24

I have a decimal value (\"133,3\") stored in string column in the database, in norway culture.

after that user changed the regional setting to english-Us. when I con

7条回答
  •  醉话见心
    2020-12-16 03:10

    Regardless of the system culture, if you specify CultureInfo.InvariantCulture you won't be able to parse "133,3" as a decimal to 133.3. The same is true for US English.

    You could just specify a Norwegian culture when parsing the value (using the overload of decimal.TryParse which takes an IFormatProvider), or (preferrably) change the field in the database to reflect the real data type (a decimal number) instead.

提交回复
热议问题