Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CultureInfo (es) ToDecimal()
Message
 
 
À
19/08/2017 04:05:55
Information générale
Forum:
C#
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01653447
Message ID:
01653508
Vues:
45
That was an interesting question indeed. Apparently we do send tnScanNo with characters. In my code I just moved TRY before the first line.

>Why would you expect to convert "P1111" to decimal ?
>Try:
public static long ToLong(this String tcString)
>        {
>            long result = 0;
>            long.TryParse(tcString, out result);
>            return result;
>        }
>
>
>
>>I am now getting this error
>>
>>System.FormatException: Input string was not in a correct format.
>> at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
>> at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
>> at System.Convert.ToDecimal(String value, IFormatProvider provider)
>>
>>
>>at this line of code
>>
>>
>>  //=====================================================================================================================
>>        public static long ToLong(this String tcString)
>>        {
>>            Decimal dDecimalValue = Convert.ToDecimal(tcString, CultureInfo.InvariantCulture);
>>            try { return (Int64)dDecimalValue; }
>>            catch { }
>>            return 0L;
>>        }
>>
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform