{
  "schemaVersion": 1,
  "slug": "rounding-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "f5b9be238ef53f3555110d897d95e9b3518b25329043a47e001b4630e4032506",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/rounding-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "R = round(V × 10^d) ÷ 10^d; R_k = round(V ÷ 10^k) × 10^k, k = 1,2,3",
    "vars": [
      [
        "V",
        "Value to round"
      ],
      [
        "d",
        "Decimal places"
      ],
      [
        "R",
        "Rounded value"
      ],
      [
        "k",
        "Power: 1 tens, 2 hundreds, 3 thousands"
      ]
    ],
    "note": "Exact halfway values round away from zero."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const roundHalfAway=(x)=>Math.sign(x)*Math.round(Math.abs(x)); const p=Math.pow(10,decimals); const rounded=roundHalfAway(value*p)/p; return{rounded,nearestTen:roundHalfAway(value/10)*10,nearestHundred:roundHalfAway(value/100)*100,nearestThousand:roundHalfAway(value/1000)*1000,difference:rounded-value};",
    "inputs": [
      {
        "name": "value",
        "type": "number",
        "default": 1234.5678,
        "min": -1000000000000000,
        "max": 1000000000000000,
        "step": 0.000001
      },
      {
        "name": "decimals",
        "type": "number",
        "default": 2,
        "min": -10,
        "max": 10,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "rounded",
        "precision": 6,
        "unit": ""
      },
      {
        "name": "nearestTen",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "nearestHundred",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "nearestThousand",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "difference",
        "precision": 6,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
