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
.
精彩评论