Column.format
formatformatlocale
Group: Conversions
Documentation
Format a Column
using a format string (or Column
of format strings).
Arguments
format
: The type-dependent format string to use to format the values. Ifformat
is""
, .to_text is used to format the value. In case of date/time columns, aDate_Time_Formatter
can be used.locale
: The locale in which the format should be interpreted. If aDate_Time_Formatter
is provided forformat
and thelocale
is set to anything else thanLocale.default
, then that locale will override the formatters locale.
Examples
Format a Column
of Dates
in the format "yyyyMMdd"
.
input = Column.from_vector "values" [Date.new 2020 12 21, Date.new 2023 4 25]
input.format "yyyyMMdd"
# ==> ["20201221", "20230425"]
Format Column
of Dates
, using format strings in a second column.
input = Column.from_vector "values" [Date.new 2020 12 21, Date.new 2023 4 25]
formats = Column.from_vector "formats" ["yyyyMMdd", "dd-MM-yyyy"]
input.format formats
# ==> ["20201221", "25-04-2023"]
Format a Column
of Integers
in the format "#,##0.00"
.
input = Column.from_vector "values" [100000000, 2222, 3]
input.format "#,##0.00"
# ==> ["100,000,000.00", "2,222.00", "3.00"]
Format a Column
of Booleans
in the format "t|f"
.
input = Column.from_vector "values" [True, False]
input.format "t|f"
# ==> ["t", "f"]
Format a Column
of numbers, using both decimal point / digit
separators and a Locale.
input = Column.from_vector "values" ["100000000", "2222", "3"] . parse numeric_type
input.format "#,##0.00" locale=(Locale.new "fr")
# ==> ["100 000 000,00", "2 222,00", "3,00"]
Errors
- If the format is incorrectly formed, or if some values in the column
did not match the expected datatype format, an
Illegal_Argument
error is thrown.
Remarks
Supported Types
Value_Type.Date
Value_Type.Date_Time
Value_Type.Time
Value_Type.Integer
Value_Type.Float
Value_Type.Boolean
Value_Type.Date
, Value_Type.Date_Time
, Value_Type.Time
format strings
See Date_Time_Formatter
for more details.
Value_Type.Integer
, Value_Type.Float
format strings
Numeric format strings are specified by the Java DecimalFormat class. See https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html for a complete format specification.
Value_Type.Boolean
format strings
Format strings for Boolean
consist of two values that represent true
and false, separated by a |
.