简体   繁体   中英

Locale/Culture problems converting string to decimal

I have a simple string received via a parameter:

"1.00"

Based on locale of visitor it sometimes converts to:

"1" or "1,00"

The second one is a problem, I always need it to be a period (dots). $,£

I am using:

decimal price = Convert.ToDecimal(stringPrice, new CultureInfo("en-GB"));

Why is it still converting to "1,00" decimal if I use en-GB culture? I tried InvariantCulture, and the same thing happens. Why is this happening? It shouldn't matter because it's on the back end, right?

The conversion is going fine - internally, you get a decimal representation of 1.00 in your variable (price). Whether you see "1,00" or something else depends on where you are outputting the variable. Please look at how you are printing it, to see how it should display.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM