Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CultureInfo (es) ToDecimal()
Message
From
20/08/2017 04:50:45
 
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01653447
Message ID:
01653511
Views:
39
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;
>>>        }
>>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform