LanguageValues and typesStandard typesMoney and banking
UnitPrice
On this page
A price per amount of something, such as £2.50 per kilo.
Use it for goods sold by weight, volume, length or area, as UK shelf labels show them. For the price of a thing you count, use Price.
Shape
One of these, each with its own fields:
| Variant | Field | Type | Required? |
|---|---|---|---|
UnitPrice.per_mass |
price |
Money |
Yes |
per |
Mass |
Yes | |
UnitPrice.per_volume |
price |
Money |
Yes |
per |
Volume |
Yes | |
UnitPrice.per_length |
price |
Money |
Yes |
per |
Length |
Yes | |
UnitPrice.per_area |
price |
Money |
Yes |
per |
Area |
Yes |
Example
UnitPrice.per_mass { price: money.from_minor(250, Currency.gbp) per: 1kg }Good to know
- Pick the variant by what you measure:
per_mass,per_volume,per_lengthorper_area. - Neither the price nor the amount can be below zero.
==tells you whether two are the same.<andlist.sort_bydon't take it.
In JSON
An object of its variant's name, as tag, and the variant's fields, in a request, a response or json.write:
{"tag":"per_mass","price":{"amount":250,"currency":"GBP"},"per":{"value":"1","unit":"kg"}}{"tag":"per_volume","price":{"amount":180,"currency":"GBP"},"per":{"value":"0.001","unit":"cubic_metre"}}{"tag":"per_length","price":{"amount":399,"currency":"GBP"},"per":{"value":"1","unit":"metre"}}
Details
Text form, storage, how it is shown, and operations
UnitPrice 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 4 columns, each named for the field, _ and its suffix. This is {"tag":"per_volume","price":{"amount":180,"currency":"GBP"},"per":{"value":"0.001","unit":"cubic_metre"}}:
| Column | Type | Holds |
|---|---|---|
<field>_kind |
text |
'per_volume' |
<field>_price |
bigint |
180 |
<field>_price_currency |
char(3) |
'GBP' |
<field>_per |
numeric(38, 9) |
0.001 |
How it is shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
{"tag":"per_mass","price":{"amount":250,"currency":"GBP"},"per":{"value":"1","unit":"kg"}} |
£2.50/1 kg |
{"tag":"per_volume","price":{"amount":180,"currency":"GBP"},"per":{"value":"0.001","unit":"cubic_metre"}} |
£1.80/0.001 m³ |
{"tag":"per_length","price":{"amount":399,"currency":"GBP"},"per":{"value":"1","unit":"metre"}} |
£3.99/1 m |
Operations
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-unit-price.md.Built from Jadpo main at aee2e8f.