Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CultureInfo (es) ToDecimal()
Message
 
 
À
Tous
Information générale
Forum:
C#
Catégorie:
Code, syntaxe and commandes
Titre:
CultureInfo (es) ToDecimal()
Divers
Thread ID:
01653447
Message ID:
01653447
Vues:
45
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform