Rounding API
Round a number to decimal places, significant digits or a multiple, with any of seven rounding rules.
POST https://api.curatedapi.com/v1/calc/math/rounding
- Version 1
- MCP tool
calc_math_rounding - Try it in the browser
Rounds exactly (no binary floating point), so 2.675 to two places with half-up gives 2.68, not the 2.67 many programs print. Choose the rule explicitly: half-up, banker's rounding (half-even), half-down, up, down (truncate), ceiling or floor.
Formula
decimals: round(x·10ⁿ)/10ⁿ; multiple: round(x/m)·m; ties per the chosen mode
- The rounding rule is the mode input; this calculator takes no options object.
Inputs
Send numbers as strings to keep every digit. options sets precision and rounding (see numbers and rounding).
| Input | Type | Description |
|---|---|---|
value required |
decimal (string) | The number to round. |
method |
decimals | significant | multiple default decimals |
What to round to. Options: decimals: to a number of decimal places (negative rounds to tens, hundreds, ...); significant: to a number of significant digits; multiple: to the nearest multiple of a step, e.g. 0.05 for cash rounding |
places |
integer | Decimal places (method decimals) or significant digits (method significant). Allowed: >= -20 and <= 60. |
multiple |
decimal (string) | Step to round to (method multiple), e.g. 0.05. Allowed: > 0. |
mode |
half_up | half_even | half_down | up | down | ceiling | floor default half_up |
Rounding rule. Options: half_up: to nearest, ties away from zero (2.5 → 3, -2.5 → -3); half_even: to nearest, ties to even (2.5 → 2, 3.5 → 4): banker's rounding; half_down: to nearest, ties towards zero (2.5 → 2); up: away from zero (2.1 → 3, -2.1 → -3); down: towards zero, i.e. truncate (2.9 → 2); ceiling: towards +∞ (2.1 → 3, -2.1 → -2); floor: towards −∞ (2.9 → 2, -2.1 → -3) |
Result
Under result in the answer, next to exactness, precision, inputs, formula, references and warnings.
| Result | Type | Description |
|---|---|---|
result | string | The rounded number, with trailing zeros kept (2.10). |
changed | boolean | False when the value was already exact at this precision. |
difference | string | result − value, exactly. |
Examples
2.675 to 2 places, half-up
curl https://api.curatedapi.com/v1/calc/math/rounding \
-H "Authorization: Bearer $CURATEDAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"value": "2.675",
"places": 2
}'
{
"calculator": "math/rounding@1",
"result": {
"result": "2.68",
"changed": true,
"difference": "0.005"
},
"exactness": {},
"precision": null,
"inputs": {
"value": "2.675",
"method": "decimals",
"places": 2,
"mode": "half_up"
},
"formula": "decimals: round(x·10ⁿ)/10ⁿ; multiple: round(x/m)·m; ties per the chosen mode",
"references": [
{
"title": "IEEE 754-2008 section 4.3: rounding-direction attributes",
"url": "https://doi.org/10.1109/IEEESTD.2008.4610935"
},
{
"title": "Rounding",
"url": "https://en.wikipedia.org/wiki/Rounding"
}
],
"warnings": []
}
Banker's rounding
curl https://api.curatedapi.com/v1/calc/math/rounding \
-H "Authorization: Bearer $CURATEDAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"value": "2.5",
"places": 0,
"mode": "half_even"
}'
{
"calculator": "math/rounding@1",
"result": {
"result": "2",
"changed": true,
"difference": "-0.5"
},
"exactness": {},
"precision": null,
"inputs": {
"value": "2.5",
"method": "decimals",
"places": 0,
"mode": "half_even"
},
"formula": "decimals: round(x·10ⁿ)/10ⁿ; multiple: round(x/m)·m; ties per the chosen mode",
"references": [
{
"title": "IEEE 754-2008 section 4.3: rounding-direction attributes",
"url": "https://doi.org/10.1109/IEEESTD.2008.4610935"
},
{
"title": "Rounding",
"url": "https://en.wikipedia.org/wiki/Rounding"
}
],
"warnings": []
}
Cash rounding to 0.05
curl https://api.curatedapi.com/v1/calc/math/rounding \
-H "Authorization: Bearer $CURATEDAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"value": "1.234",
"method": "multiple",
"multiple": "0.05"
}'
{
"calculator": "math/rounding@1",
"result": {
"result": "1.25",
"changed": true,
"difference": "0.016"
},
"exactness": {},
"precision": null,
"inputs": {
"value": "1.234",
"method": "multiple",
"multiple": "0.05",
"mode": "half_up"
},
"formula": "decimals: round(x·10ⁿ)/10ⁿ; multiple: round(x/m)·m; ties per the chosen mode",
"references": [
{
"title": "IEEE 754-2008 section 4.3: rounding-direction attributes",
"url": "https://doi.org/10.1109/IEEESTD.2008.4610935"
},
{
"title": "Rounding",
"url": "https://en.wikipedia.org/wiki/Rounding"
}
],
"warnings": []
}
References
Results follow each calculator's documented rules and the sources listed. They are not financial, tax or legal advice. Check that the rules fit your case before you rely on a result. See the terms.
Errors share one format; see errors. Billing, retries and batches work the same for every endpoint.