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:
{
"value": "500",
"from": "mg",
"to": "g"
}
Response:
{
"result": {
"numerator": "1",
"denominator": "2"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "mass-convert",
"version": "1.0.0",
"input": {
"value": "500",
"from": "mg",
"to": "g"
}
}
HTTP (no key)
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.
CLI
node cli.mjs run mass-convert 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Mass compare: Compare two mixed-unit canonical integer mass amounts using exact nanogram BigInt values.
- Byte size convert: Convert a non-negative integer byte size between IEC binary units as an exact rational.
- Length convert: Convert a canonical integer length between exact SI and international customary units.
- Mass add: Add mixed-unit canonical integer mass amounts and express the sum in a target unit as a reduced rational.
- Temperature compare: Compare two temperatures in C, F, or K by converting both to Kelvin rationals.
- Temperature convert: Convert a decimal temperature between Celsius, Fahrenheit, and Kelvin as an exact rational.