← All procedures

rational.fromNumber

This function reads a finite number as JavaScript prints it. That text is the shortest decimal that reads back as the same number. Thus `0.1` gives 1/10, not the exact value of the double. Use `fromFloat` for the exact value.

CLI
Package
@procedures/rational · README
Path
["rational","fromNumber"]
CLI
mark rational fromNumber --value <number>
As data
{"$proc":["rational","fromNumber"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/rational/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["rational","fromNumber"], { value: 1 });
console.log(JSON.stringify(result));

From the command line

$ mark rational fromNumber --value <number>

As data, in a program

{ "$proc": ["rational", "fromNumber"], "input": { "value": 1 } }

Input

FieldTypeRequiredDefaultDescription
valuenumberyes

Output

FieldTypeRequiredDefaultDescription
nstringyes
dstringyes
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "value": {
        "type": "number"
      }
    },
    "required": [
      "value"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "object",
    "properties": {
      "n": {
        "type": "string",
        "pattern": "^-?(0|[1-9][0-9]*)$",
        "x-procedures-codec": "bigint"
      },
      "d": {
        "type": "string",
        "pattern": "^-?(0|[1-9][0-9]*)$",
        "x-procedures-codec": "bigint"
      }
    },
    "required": [
      "n",
      "d"
    ],
    "additionalProperties": {}
  }
}