class ICU::NumberFormatter
- ICU::NumberFormatter
- Reference
- Object
Overview
Number Formatter
This class provides a facility for formatting and parsing numbers.
Usage
nf = ICU::NumberFormatter.new("en_US")
nf.format(1234.56) # => "1,234.56"
nf.parse("1,234.56") # => 1234.56
See also
Defined in:
icu/number_formatter.crConstructors
-
.new(locale : String = "en_US", format_style : FormatStyle = FormatStyle::Default)
Creates a new NumberFormatter.
Instance Method Summary
- #finalize
-
#format(number : Float64, currency_code : String) : String
Formats a number with a currency code (3 letters code, see ISO 4217) into a string.
-
#format(number : Float64) : String
nf = ICU::NumberFormatter.new("en_US") nf.format(1234.56) # => "1,234.56"
-
#format(number : Int64) : String
Formats a number into a string.
-
#get_attribute(attribute : FormatAttribute) : Int32
Gets an attribute of the number formatter.
-
#parse_float(text : String) : Float64
Parses a string into a floating point number.
-
#parse_float_with_currency(text : String) : MonetaryAmount
Parses a string into a monetary amount.
-
#parse_int(text : String) : Int64
Parses a string into an integer number.
-
#set_attribute(attribute : FormatAttribute, value : Int32)
Sets an attribute of the number formatter.
Constructor Detail
Creates a new NumberFormatter.
nf = ICU::NumberFormatter.new("en_US")
nf = ICU::NumberFormatter.new("fr_FR", ICU::NumberFormatter::FormatStyle::Currency)
Instance Method Detail
Formats a number with a currency code (3 letters code, see ISO 4217) into a string.
nf = ICU::NumberFormatter.new("en_US", ICU::NumberFormatter::FormatStyle::Currency)
nf.format(1234.56, "USD") # => "$1,234.56"
nf = ICU::NumberFormatter.new("en_US")
nf.format(1234.56) # => "1,234.56"
Formats a number into a string.
nf = ICU::NumberFormatter.new("en_US")
nf.format(1234) # => "1,234"
Gets an attribute of the number formatter.
nf.get_attribute(ICU::NumberFormatter::FormatAttribute::GroupingUsed) # => 0
Parses a string into a floating point number.
nf = ICU::NumberFormatter.new("en_US")
nf.parse("1,234.56") # => 1234.56
Parses a string into a monetary amount.
nf.parse_float_with_currency("$1,234.56") # => ICU::NumberFormatter::MonetaryAmount.new(1234.56, "USD")
Parses a string into an integer number.
nf = ICU::NumberFormatter.new("en_US")
nf.parse("1,234.56") # => 1234
Sets an attribute of the number formatter.
nf.set_attribute(ICU::NumberFormatter::FormatAttribute::GroupingUsed, 0)