Precision & numeric values
Correct vs invalid
{"value": "0.1", "from": "m", "to": "cm"}
Not valid in v1:
{"value": 0.1, "from": "m", "to": "cm"}
Accepted formats
| Format | Example | Accepted |
|---|---|---|
| Integer | "10" | Yes |
| Negative | "-10" | Only where the category allows it (for example temperature). Most categories, such as length and mass, return OUT_OF_RANGE |
| Decimal | "10.5" | Yes |
| Scientific | "1.25e6" | Yes |
| NaN / Infinity | "NaN" | No |
| Comma-separated | "1,000" | No |
| Fraction | "1/2" | No |
| With unit suffix | "10 kg" | No |
Input limits
- At most 256 characters before trimming whitespace
- At most 100 significant digits
- An explicit exponent of at most 1000 in absolute value
- Request bodies are limited to 64 KiB (
PAYLOAD_TOO_LARGE, HTTP 413)
Engine precision
Without decimals, terminating results keep
their full decimal value. Nonterminating results use 40 significant digits
with half-even rounding. Example:
{
"value": "10",
"from": "kg",
"to": "lb"
}
// result.value → "22.04622621848775807229738013450270338542"
Optional decimals
Pass decimals (integer 0–40) on GET query, POST body, or each
batch item to round only result.value
after conversion. Rounding is half-even (same mode as the engine).
input.value is not rounded, but it is
echoed in canonical form (for example "1.25e6"
comes back as "1250000").
curl "https://api.unifyunits.com/v1/convert?value=10&from=kg&to=lb&decimals=2" \
-H "Authorization: Bearer $UNIFYUNITS_API_KEY"
# result.value → "22.05"
{"value": "10", "from": "kg", "to": "lb", "decimals": 2}
Omit decimals for the full engine string.
Unknown keys such as precision are rejected.
When decimals is set, large or tiny results
that the engine would emit in scientific notation are expanded to a fixed
decimal string (for example "1e+22" with
decimals: 2 becomes
"10000000000000000000000.00").
Temperature
Temperature uses affine conversion (offset + scale). Results are deterministic for the same input under the same API version.
| Input | From | To | Result |
|---|---|---|---|
"32" | F | C | "0" |
"0" | C | K | "273.15" |
"-40" | C | F | "-40" |