Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CultureInfo (es) ToDecimal()
Message
De
20/08/2017 04:50:45
 
 
Information générale
Forum:
C#
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01653447
Message ID:
01653511
Vues:
38
This message has been marked as a message which has helped to the initial question of the thread.
Why bother converting to Decimal when you want a long ?

>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;
>>>        }
>>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform