Float.parse
Float.parsetextlocale format
Group: Conversions
Aliases: from text
Documentation
Parses a string into a Float, returning a Number_Parse_Error if the text does not represent a valid Float.
Arguments
text: The text to parse into aFloat.locale: The locale that specifies the format to use when parsing.format: The Java-style format to use to parse the string.
Examples
Parse a Float with no locale specifier.
Float.parse "123456789.87654"
# => 123456789.87654
Parse a Float with the default locale.
Float.parse "123,456,789.87654" locale=Locale.default
# => 123456789.87654
Parse a Float with the US locale.
Float.parse "123,456,789.87654" locale=Locale.us
# => 123456789.87654
Parse a Float with the Italy locale.
Float.parse "123.456.789,87654" locale=Locale.italy
# => 123456789.87654
Parse a Float with an explicit negative number format.
Float.parse "(123,456,789.654)" format="###,###.##;(###,###.##)"
# => -123456789.654
Errors
- If
textis incorrectly formatted, aNumber_Parse_Erroris thrown. - If
formatis incorrectly formatted (or uses digit separators that differ from the ones specified by the locale), anIllegal_Argumentis thrown.