Locale formatting
Add format_locale to a request and the
result gains a formatted string ready to
show to people. The exact value is never
changed, so you can keep computing with it.
bash
curl "https://api.unifyunits.com/v1/convert" \
-X POST \
-H "Authorization: Bearer $UNIFYUNITS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"value":"1500","from":"m","to":"km","format_locale":"de-DE"}'
json
{
"data": {
"input": { "value": "1500", "unit": "m" },
"result": { "value": "1.5", "unit": "km", "formatted": "1,5 km" },
"category": "length"
}
}
Examples
| Result | format_locale | formatted |
|---|---|---|
| 1.5 km | de-DE | 1,5 km |
| 1234.56 kg | de | 1.234,56 kg |
| 1234.56 kg | en-US | 1,234.56 kg |
| 64.00 GBP (currency) | de-DE | 64,00 £ |
Rules
-
Works on convert, batch (applied to every successful item), parse (when
tois set), currency conversion, and substance conversion. Pass it as a query parameter on GET requests. Normalize and unit price do not format output. -
The digits shown are exactly the digits of
value, trailing zeros included. Usedecimalsto control them:decimals: 2gives64,00 £, not64 £. -
Units that have a standard localized name (metres, kilograms, litres,
miles, and others) use it. Other units show the number followed by the
unit symbol, for example
101.325 kPa. Currencies use the locale's symbol and placement. -
A language tag that is malformed or unknown returns
INVALID_REQUEST(HTTP 400). Use hyphens, for examplede-DE, notde_DE. -
Requires the Developer plan or higher
(
PLAN_REQUIREDotherwise). -
This is separate from the
localeoption of Normalize and unit price, which controls how input numbers like1,5are read.