# Mass convert

`mass-convert` · version 1.0.0 · Units & sizes · free, no key needed

Convert a canonical integer mass amount between exact nanogram-based units as a reduced rational.

**Use when you need to: mass convert · convert mass units · convert grams kilograms pounds.**

## Supported

- mass convert
- convert mass units
- convert grams kilograms pounds

## Not supported

- troy ounces or pounds
- stone
- short tons
- long tons
- floating-point mass
- SI prefixes other than ng ug mg g kg t

## Behavior

- value is a canonical integer string amount in the from unit; negative amounts are allowed and -0 canonicalizes to 0.
- Units are exactly ng, ug, mg, g, kg, t, oz, and lb from MASS_NG.
- t is the metric tonne (1000 kg); lb is the international avoirdupois pound (exactly 0.45359237 kg); oz is 1/16 lb.
- Conversion is the exact rational value * from_ng / to_ng, reduced by gcd, with the sign only on the numerator.
- The output is a canonical rational {numerator, denominator} expressed in the to unit.
- Unknown units, unknown fields, non-canonical integers, and results whose reduced components exceed 1000 digits are rejected.

## Input

- `value` (string, required): max length 1001; pattern `^-?(0|[1-9][0-9]*)$`
- `from` (one of "ng", "ug", "mg", "g", "kg", "t", "oz", "lb", required)
- `to` (one of "ng", "ug", "mg", "g", "kg", "t", "oz", "lb", required)

## Output

- `numerator` (string, required): pattern `^(0|-?[1-9][0-9]*)$`
- `denominator` (string, required): pattern `^[1-9][0-9]*$`

## Limits

- max digits: 1000

## Example

Request input:

```json
{
  "value": "500",
  "from": "mg",
  "to": "g"
}
```

Response:

```json
{
  "result": {
    "numerator": "1",
    "denominator": "2"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "mass-convert",
  "version": "1.0.0",
  "input": {
    "value": "500",
    "from": "mg",
    "to": "g"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/mass-convert/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"value":"500","from":"mg","to":"g"}'
```

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

### CLI

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

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

## Related tools

- [Mass compare](/tools/mass-compare): Compare two mixed-unit canonical integer mass amounts using exact nanogram BigInt values.
- [Byte size convert](/tools/bytesize-convert): Convert a non-negative integer byte size between IEC binary units as an exact rational.
- [Length convert](/tools/length-convert): Convert a canonical integer length between exact SI and international customary units.
- [Mass add](/tools/mass-add): Add mixed-unit canonical integer mass amounts and express the sum in a target unit as a reduced rational.
- [Temperature compare](/tools/temperature-compare): Compare two temperatures in C, F, or K by converting both to Kelvin rationals.
- [Temperature convert](/tools/temperature-convert): Convert a decimal temperature between Celsius, Fahrenheit, and Kelvin as an exact rational.
