Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CultureInfo (es) ToDecimal()
Message
 
 
To
All
General information
Forum:
C#
Category:
Coding, syntax and commands
Title:
CultureInfo (es) ToDecimal()
Miscellaneous
Thread ID:
01653447
Message ID:
01653447
Views:
46
UPDATE. So, I searched the project for ToDecimal and added CultureInfo.InvariantCulture to all the conversions. I'm going to do that for ToFloat and ToDouble as well now.


Hi everybody,

I have the following lines of code:
else if (SqlDbType.Decimal == parameterType || SqlDbType.SmallMoney == parameterType)
            {
                if (parameterSize > 0)
                    parameter = new SqlParameter("@" + parameterName, parameterType, parameterSize);
                else
                    parameter = new SqlParameter("@" + parameterName, parameterType);
                parameter.Value = parameterValue.ToDecimal();
            }
My parameterValue is a string
-993.13
When the last line is executed, I'm getting

Parameter.Value = + SqlValue {-99313} object {System.Data.SqlTypes.SqlDecimal}

Prior to executing that code I executed the following:
CultureInfo.DefaultThreadCurrentCulture = culture;
                    CultureInfo.DefaultThreadCurrentUICulture = culture;

                    Thread.CurrentThread.CurrentCulture = culture;
                    Thread.CurrentThread.CurrentUICulture = culture;
and my culture was 'es'.

So, apparently in es converting 993.13 to Decimal produced 99313 and the . was ignored.

I need to treat it as normal decimal value. I'm going to research if ToDecimal allows specifying English culture and looks like we would need to be careful with all parsing and converting of the string values into decimal.

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform