LanguageValues and typesStandard typesMoney and banking
Price
On this page
An amount, and whether it includes tax.
Use it for what you charge. It stops a price with tax being taken for one without. For a plain amount, such as a refund or a balance, use Money. For a price per kilo, use UnitPrice.
Shape
| Field | Type | Required? |
|---|---|---|
amount |
Money |
Yes |
includes_tax |
Bool |
Yes |
Example
Price { amount: money.from_minor(1050, Currency.gbp) includes_tax: true }This operation gives one: money.apply_discount.
Good to know
- The amount can't be below zero.
text.formatshows only the amount,£10.50. It doesn't say whether tax is included, so add that wording yourself.==tells you whether two are the same.<andlist.sort_bydon't take it, so sort by one of its parts instead.
In JSON
An object of its parts, in a request, a response or json.write:
{"amount":{"amount":1050,"currency":"GBP"},"includes_tax":true}{"amount":{"amount":875,"currency":"GBP"},"includes_tax":false}{"amount":{"amount":1200,"currency":"EUR"},"includes_tax":true}
Details
Text form, storage, how it is shown, and operations
Price is in the group Money and banking, and has been in Jadpo since 0.1.0.
Text form
It has no single text form, so text.from and text.parse don't take it.
How it is stored
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 |
How it is 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.
It also takes text.format, json.read, json.write and ==. How every standard type behaves says how they work.
Markdown for agents: /docs/types/type-price.md.Built from Jadpo main at aee2e8f.