KScript docs
EN

money fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.amountnumberThe amount as a number, without the currency: 9.5 for GBP 9.50.
.currencycurrencyThe currency the amount is in: GBP.

From KScript.Core

#money->add(other: money, rate?: number) → money

Adds another amount in this amount's currency. For a foreign amount, rate gives units of the receiving currency per unit of the other. Omitting rate uses the receiving amount's rates table, then @set_exchange_rate(), then the project's money.exchange_rates setting. The incoming amount rounds to the nearest minor unit, with ties away from zero.
ParameterTakes
other requiredmoney
rate optionalnumber

Arguments can be named: ->add(…, rate: …).

Example
<let name="x" type="money" value="'GBP 10.00'" />
<let name="euros" type="money" value="'EUR 5.00'" />
<echo>{ $x->add($euros, rate: 0.8) }</echo>
$x: money = 'GBP 10.00'
$euros: money = 'EUR 5.00'
echo $x->add($euros, rate: 0.8)

#money->allocate(ratios: list) → money[]

The amount shared by these ratios, in parts that add up to it exactly: GBP 10.00 by [1, 1, 2] is GBP 2.50, GBP 2.50 and GBP 5.00.
ParameterTakes
ratios requiredlist
Example
<let name="x" type="money" value="'GBP 10.00'" />
<echo>{ $x->allocate([1, 1, 2]) }</echo>
$x: money = 'GBP 10.00'
echo $x->allocate([1, 1, 2])

#money->format(locale?: string) → string

The amount written for a locale, or the current one: £10.00 in en, 10,00 £ in fr.
ParameterTakes
locale optionalstring
Example
<let name="x" type="money" value="'GBP 10.00'" />
<echo>{ $x->format('en') } { $x->format('fr') }</echo>
$x: money = 'GBP 10.00'
echo "{ $x->format('en') } { $x->format('fr') }"

#money->split(parts: number) → money[]

The amount shared into this many parts that add up to it exactly: GBP 10.00 in 3 is GBP 3.34, GBP 3.33 and GBP 3.33.
ParameterTakes
parts requirednumber
Example
<let name="x" type="money" value="'GBP 10.00'" />
<echo>{ $x->split(3) }</echo>
$x: money = 'GBP 10.00'
echo $x->split(3)

#money->subtract(other: money, rate?: number) → money

Takes another amount away, in this amount's currency, converting a foreign amount the same way ->add() does: rate, then the rates table, @set_exchange_rate() and money.exchange_rates.
ParameterTakes
other requiredmoney
rate optionalnumber

Arguments can be named: ->subtract(…, rate: …).

Example
<let name="x" type="money" value="'GBP 10.00'" />
<let name="fee" type="money" value="'GBP 0.50'" />
<echo>{ $x->subtract($fee) }</echo>
$x: money = 'GBP 10.00'
$fee: money = 'GBP 0.50'
echo $x->subtract($fee)

Methods from any