Skip to main content

Decimal.parse

Decimal.parsetextlocale

Group: conversions
Aliases: from text

Documentation

Parses a string into a Decimal, returning a Number_Parse_Error if the text does not represent a valid Decimal.

Arguments

  • text: The text to parse into a Decimal.
  • locale: The locale that specifies the format to use when parsing.

Examples

Parse a Decimal with no local specifier.

      Decimal.parse "123456789.87654"
# => 123456789.87654

Parse a Decimal with the default locale.

      Decimal.parse "123,456,789.87654" locale=Locale.default
# => 123456789.87654

Parse a Decimal with the US locale.

      Decimal.parse "123,456,789.87654" locale=Locale.us
# => 123456789.87654

Parse a Decimal with the Italy locale.

      Decimal.parse "123.456.789,87654" locale=Locale.italy
# => 123456789.87654

Errors

  • If text is incorrectly formatted, a Number_Parse_Error is thrown.