Price
An amount and whether it includes tax, so a gross price is never taken for a net one: shown as its amount, £10.50. The amount is never below 0.
Money and banking; not ordered; since Jadpo 0.1.0.
Make one
Build one from its fields, Price { amount: ... includes_tax: ... }.
This operation gives one: money.apply_discount.
Fields
| Field | Type |
|---|---|
amount |
Money |
includes_tax |
Bool |
Text, JSON and storage
It has no single text form, so text.from and text.parse don't take it. JSON sends an object of its parts.
| JSON |
|---|
{"amount":{"amount":1050,"currency":"GBP"},"includes_tax":true} |
{"amount":{"amount":875,"currency":"GBP"},"includes_tax":false} |
{"amount":{"amount":1200,"currency":"EUR"},"includes_tax":true} |
It is stored in 3 columns, each named for the field, _ and its suffix. This is {"amount":{"amount":875,"currency":"GBP"},"includes_tax":false}:
| Column | Type | Holds |
|---|---|---|
<field>_amount |
bigint |
875 |
<field>_currency |
char(3) |
'GBP' |
<field>_includes_tax |
boolean |
FALSE |
Shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
{"amount":{"amount":1050,"currency":"GBP"},"includes_tax":true} |
£10.50 |
{"amount":{"amount":875,"currency":"GBP"},"includes_tax":false} |
£8.75 |
{"amount":{"amount":1200,"currency":"EUR"},"includes_tax":true} |
€12.00 |
Operations
money.apply_discount(price: Price, discount: Discount) -> Price:pricewithdiscounttaken off its amount, keeping whether it includes tax: an amount off in the price's currency, or that percentage of the amount, rounded half to even to a minor unit, so 15% off £10.05 is £1.51 off. More off than the price leaves nothing. It fails withcurrency_mismatchfor an amount off in another currency.
Like every standard type, it also has the contract's own operations: text.format, json.read, json.write and ==. It isn't ordered, so < and sorting don't take it. Every standard type meets one contract says how they work.
Markdown for agents: /docs/types/type-price.md.Built from Jadpo main at e00e61f.