Skip to main content

Decimal.format

formatformatlocale

Group: Conversions

Documentation

Converts a Decimal to a string, using the Java DecimalFormat formatter. For details about the DecimalFormat format specifier, see https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html.

Arguments

  • format: The Java-style formatting specifier.
  • locale: Species the Locale to use for locale-specific number formatting.

Examples

Convert a Decimal to a string using the default format and locale.

      Decimal.new "123456789.87654" . format
# => "123,456,789.87654"

Convert a Decimal to a string using a specific locale.

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

Convert a Decimal to a string using a specific format string.

      Decimal.new "123456789.87654" . format format="#,###.##"
# => 123,456,789.88"