Decimal divide
decimal-divide · version 1.0.0 · Money & pricing · free, no key needed
Divide two decimal strings exactly, rounding the quotient once to a fixed scale, and report the exact remainder.
Use when you need to: divide two decimals exactly · exact decimal division with rounding · quotient and remainder of decimal division.
Decide before calling
Read the versioned contract and the supported scope below. Reuse decimal-divide@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use decimal-divide@1.0.0 for divide two decimals exactly. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- divide two decimals exactly
- exact decimal division with rounding
- quotient and remainder of decimal division
- unit price from total and quantity
- divide to n decimal places
- split an amount by a divisor to cents
- decimal division rounding mode
- average price per unit exact
Not supported
- integer euclidean division of huge numbers
- evaluating formulas with several operations
- currency conversion with exchange rates
- floating point or scientific notation input
Behavior
- Decimal strings match ^-?(0|[1-9][0-9]*)(\.[0-9]+)?$: no plus sign, exponent, leading zeros, leading or trailing point, whitespace or separators. A JSON number where a decimal string is required is invalid_input (wrong type).
- A decimal string longer than 62 UTF-16 code units -> limit_exceeded, checked before the grammar. Otherwise a grammar failure, more than 60 digits in total, or more than 40 fraction digits -> invalid_input.
- Zero has no sign: "-0", "-0.00" and any all-zero value are zero and are emitted as "0" (canonical) or "0.00" (fixed scale), never "-0".
- All four fields are required. The exact rational quotient dividend/divisor is rounded once to scale fraction digits with the given mode.
- Rounding modes act on the exact rational result and are: half_even (ties to the even neighbour), half_up (ties away from zero), half_down (ties toward zero), half_ceiling (ties toward +infinity), half_floor (ties toward -infinity), up (away from zero), down (toward zero), ceiling (toward +infinity), floor (toward -infinity), unnecessary (any inexact result -> not_computable with details.reason "rounding_necessary").
- A result rounded to scale s is written with exactly s fraction digits (no fraction and no point when s is 0); a result with no scale is canonical: trailing fraction zeros are stripped and an integer has no point.
- remainder = dividend - value * divisor, exact and canonical (trailing fraction zeros stripped, "0" when zero). Its sign follows from the rounding direction: rounding up gives a negative remainder for a positive divisor.
- A zero divisor (including "0.00" and "-0") -> not_computable with details.reason "division_by_zero", even when the dividend is also zero. This is checked after all input validation.
- rounding "unnecessary" with an inexact quotient -> not_computable with details.reason "rounding_necessary".
- Validation order (each vector carries a single fault): input not an object; unknown field; missing required field; field types, ranges and decimal-string limits; scale/rounding pairing; then domain errors (not_computable) last.
Input
dividend(string, required): min length 1; max length 62; pattern^-?(0|[1-9][0-9]*)(\.[0-9]+)?$; Number being divided, decimal string.divisor(string, required): min length 1; max length 62; pattern^-?(0|[1-9][0-9]*)(\.[0-9]+)?$; Number to divide by, decimal string; must not be zero.scale(integer, required): min 0; max 40; Number of fraction digits in the quotient.rounding(one of "half_even", "half_up", "half_down", "half_ceiling", "half_floor", "up", "down", "ceiling", "floor", "unnecessary", required): Rounding mode applied to the exact quotient.
Output
value(string, required): min length 1; max length 200; Quotient rounded to scale, written with exactly scale fraction digits.exact(boolean, required): true when the rounded quotient equals the exact quotient.remainder(string, required): min length 1; max length 200; dividend - value * divisor as an exact canonical decimal; negative when the quotient was rounded up past the exact value.
Limits
- max decimal chars: 62
- max decimal digits: 60
- max fraction digits: 40
- max scale: 40
Example
Request input:
{
"dividend": "10",
"divisor": "3",
"scale": 2,
"rounding": "half_even"
}
Response:
{
"result": {
"value": "3.33",
"exact": false,
"remainder": "0.01"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "decimal-divide",
"version": "1.0.0",
"input": {
"dividend": "10",
"divisor": "3",
"scale": 2,
"rounding": "half_even"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/decimal-divide/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"dividend":"10","divisor":"3","scale":2,"rounding":"half_even"}'
The machine-readable contract is at /v1/tools/decimal-divide/versions/1.0.0.
CLI
node cli.mjs run decimal-divide 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Decimal multiply: Multiply two decimal strings exactly, optionally rounding the product once to a fixed scale with a chosen mode.
- Decimal expression evaluate: Evaluate a decimal arithmetic expression exactly with variables, abs, min, max and round, rounding once at the end.
- Decimal power: Raise a decimal string to an integer power exactly, with optional single rounding to a fixed scale.
- Vat net gross convert: Convert a net or gross amount at a VAT rate into a net, VAT and gross triple that adds up exactly at currency precision.
- Decimal root: Real nth root (2 to 100) of a decimal string, correctly rounded once to a fixed scale with an explicit mode.
- Decimal sum: Add up to 10,000 decimal strings exactly and report count, smallest and largest, with optional final rounding.