STRING::FORMAT_MONEY
1g 2023-11-28 laplante@plcb.ca GOWEB/STRING — Format Numbers as Currency Stringstitle: “STRING::FORMAT_MONEY” version: “1.0.0” date: 2023-11-28 author: “laplante@plcb.ca” section: “1g” category: “GOWEB/STRING”
string::format_money Format Numbers as Currency Strings
string::format_money(expression [, error: bool, position: "after|before", precision: int, symbol: string, lg: "fr", thousand: string, decimal: string])
format_money(expression [, ...])
string::formatMoney(expression [, error: bool, position: "after|before", precision: int, symbol: string, lg: "fr", thousand: string, decimal: string])
formatMoney(expression [, ...])
The format_money
function returns a number formatted as a currency string with customizable precision, thousand separators, decimal separators, currency symbols, and symbol placement.
When lg
is set to "fr"
, French-style formatting rules are automatically applied.
expression (number, required) The numeric value(s) to format.
error (bool, optional)
If set to true
, errors are returned in the output. Default is false
.
precision (int, optional)
Number of decimal digits. Default is 2
.
symbol (string, optional)
Currency symbol. Default is "$"
.
thousand (string, optional)
Thousands separator. Default is ","
.
decimal (string, optional)
Decimal separator. Default is "."
.
position (string, optional) Placement of the currency symbol relative to the number:
"before"
→ symbol before the number (default)."after"
→ symbol after the number.lg (string, optional)
If set to "fr"
, applies French formatting defaults:
precision = 2
symbol = " $"
thousand = " "
(space)decimal = ","
position = "after"
res={{
format_money(134567.67); "\n";
format_money(decimal:",", 134567.67); "\n";
format_money(thousand:"#", decimal:",", 134567.67); "\n";
format_money(precision:1, thousand:"#", decimal:",", 134567.67); "\n";
format_money(symbol:"£ ", precision:1, thousand:"#", decimal:",", 134567.67); "\n";
format_money(lg:"fr", 134567.67); "\n";
format_money(lg:"fr", 134567.67, -123456.789); "\n";
format_money(position:"after", symbol:"£ ", precision:1, thousand:"#", decimal:",", 134567.67); "\n";
format_money(position:"before", symbol:"£ ", precision:1, thousand:"#", decimal:",", 134567.67); "\n";
}};
Returns:
$134,567.67
$134,567,67
$134#567,67
$134#567,7
£ 134#567,7
134 567,67 $
["134 567,67 $","-123 456,79 $"]
134#567,7£
£ 134#567,7