Parse string using "." as the thousands separator and " " as the decimal separator. : Decimal Parse « Data Types « VB.Net






Parse string using "." as the thousands separator and " " as the decimal separator.

  

Imports System
Imports Microsoft.VisualBasic
Imports System.Globalization
Module MainClass
    Sub Main( )
        Dim value As String
        Dim number As Decimal
        Dim style As NumberStyles
        Dim provider As CultureInfo
        

        value = "999 888,12"
        style = NumberStyles.AllowDecimalPoint Or NumberStyles.AllowThousands
        provider = New CultureInfo("fr-FR")
        
        number = Decimal.Parse(value, style, provider)  
        Console.WriteLine("'{0}' converted to {1}.", value, number)
        
        Try
           number = Decimal.Parse(value, style, CultureInfo.InvariantCulture)  
           Console.WriteLine("'{0}' converted to {1}.", value, number)
        Catch e As FormatException
           Console.WriteLine("Unable to parse '{0}'.", value)
        End Try

    End Sub
End Module 

   
    
  








Related examples in the same category

1.Decimal.Parse Method Converts string to Decimal using the specified style and culture-specific format.
2.Decimal.TryParse Method Converts string to Decimal
3.Decimal.TryParse Method (String, NumberStyles, IFormatProvider, Decimal)