开发者

Converting swedish string to currency not converting properly

开发者 https://www.devze.com 2023-03-15 18:43 出处:网络
I am trying to convert \"-10,00\" from a string into a currency using the Swedish culture. Here is my code:

I am trying to convert "-10,00" from a string into a currency using the Swedish culture. Here is my code:

ByVal ci As System.Globalization.CultureInfo("sv-SE")
Convert.ToDecimal("-10,00").ToString("C", ci)

The output from the above code is: -1.000,00 kr, which is wrong. It should be -10,00 kr. Is there anything wrong with my approach?

Solution:

The solution is to pass the cultureInfo into the ToDecimal function as a second parameter.

ByVal ci As System.Globalization.CultureInfo开发者_如何学Python("sv-SE")
Convert.ToDecimal("-10,00", ci).ToString("C", ci)


The C format specifier includes two decimal places.
To get rid of them, use C0.

0

精彩评论

暂无评论...
验证码 换一张
取 消