# Decimal multiply

`decimal-multiply` · version 1.0.0 · Money & pricing · free, no key needed

Multiply two decimal strings exactly, optionally rounding the product once to a fixed scale with a chosen mode.

**Use when you need to: multiply two decimals exactly · exact decimal multiplication · price times quantity exact.**

## Decide before calling

Read the [versioned contract](/v1/tools/decimal-multiply/versions/1.0.0) and the supported scope below. Reuse `decimal-multiply@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-multiply@1.0.0` for multiply 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

- multiply two decimals exactly
- exact decimal multiplication
- price times quantity exact
- multiply money without floating point error
- multiply decimals and round to 2 places
- unit price multiplied by quantity
- decimal product with rounding mode
- line total exact multiply

## Not supported

- floating point or scientific notation input
- multiplying more than two numbers or evaluating a formula
- percentage calculations
- currency conversion with exchange rates

## 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".
- Both a and b are multiplied as exact rationals; the product is exact (at most 120 digits, so no result-size limit can trigger).
- scale and rounding must appear together or not at all; exactly one of them present -> invalid_input. scale is a JSON integer 0..40 and rounding one of the ten mode names; anything else -> invalid_input.
- With no scale and no rounding the value is the exact canonical product and exact is true (1.20 * 3 -> "3.6"; use scale 2 to obtain "3.60").
- With scale and rounding the exact product is rounded once to scale fraction digits. exact is true iff that rounding changed nothing.
- 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.
- 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.
- rounding "unnecessary" with an inexact product -> not_computable with details.reason "rounding_necessary".

## Input

- `a` (string, required): min length 1; max length 62; pattern `^-?(0|[1-9][0-9]*)(\.[0-9]+)?$`; First factor as a decimal string.
- `b` (string, required): min length 1; max length 62; pattern `^-?(0|[1-9][0-9]*)(\.[0-9]+)?$`; Second factor as a decimal string.
- `scale` (integer, optional): min 0; max 40; Fraction digits of the result. Must be given together with rounding; omit both for the exact product.
- `rounding` (one of "half_even", "half_up", "half_down", "half_ceiling", "half_floor", "up", "down", "ceiling", "floor", "unnecessary", optional): Rounding mode applied to the exact product. Must be given together with scale.

## Output

- `value` (string, required): min length 1; max length 200; The product: canonical when no scale was given, otherwise fixed at scale fraction digits.
- `exact` (boolean, required): true when the reported value equals the exact product (no digits were changed by rounding).

## Limits

- max decimal chars: 62
- max decimal digits: 60
- max fraction digits: 40
- max scale: 40

## Example

Request input:

```json
{
  "a": "19.99",
  "b": "3"
}
```

Response:

```json
{
  "result": {
    "value": "59.97",
    "exact": true
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "decimal-multiply",
  "version": "1.0.0",
  "input": {
    "a": "19.99",
    "b": "3"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/decimal-multiply/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"a":"19.99","b":"3"}'
```

The machine-readable contract is at [/v1/tools/decimal-multiply/versions/1.0.0](/v1/tools/decimal-multiply/versions/1.0.0).

### CLI

```sh
node cli.mjs run decimal-multiply 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Decimal divide](/tools/decimal-divide): Divide two decimal strings exactly, rounding the quotient once to a fixed scale, and report the exact remainder.
- [Decimal expression evaluate](/tools/decimal-expression-evaluate): Evaluate a decimal arithmetic expression exactly with variables, abs, min, max and round, rounding once at the end.
- [Decimal sum](/tools/decimal-sum): Add up to 10,000 decimal strings exactly and report count, smallest and largest, with optional final rounding.
- [Decimal root](/tools/decimal-root): Real nth root (2 to 100) of a decimal string, correctly rounded once to a fixed scale with an explicit mode.
- [Decimal power](/tools/decimal-power): Raise a decimal string to an integer power exactly, with optional single rounding to a fixed scale.
- [Invoice totals compute](/tools/invoice-totals-compute): Compute invoice line nets, tax breakdown by rate and totals with per-line or per-rate rounding, net or gross prices.
