How do I convert string to numerical value types?
Category: System, viewed: 2K time(s).
This examples show you how to convert string to its equivalent numerical values. To convert string into number type we can use the Parse method of the desired type such as the Int32.Parse(), Double.Parse().
The static method Parse() is derived from the ValueType data type allow easy conversion from a string value to the specific value type. Type that support the Parse() method including Boolean, Byte, Decimal, Double, Int16, Int32, Int64, SByte, Single, UInt16, UInt32, UInt64.
Beside passing the string value to the Parse() method we can also pass a NumberStyles flag. This allows the Parse() method to handle specific properties of a number such as decimal point, currency symbol and leading or trailing signs.