MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / fromRoman

Function fromRoman

src/compute-engine/numerics/strings.ts:1–30  ·  view source on GitHub ↗
(roman: string)

Source from the content-addressed store, hash-verified

1import type { BigDecimal } from '../../big-decimal/index.js';
2import type { DisplayDigits } from '../types-kernel-serialization.js';
3
4/**
5 * Round a value to `n` significant figures, returning a value of the same kind
6 * (used by the number-display `{ significant: n }` control).
7 *
8 * Truncation only — no trailing-zero padding. For machine numbers, the value
9 * is round-tripped through `parseFloat(x.toPrecision(n))` so that the caller
10 * can serialize it through the normal string path; this avoids the exponential
11 * notation that `Number.prototype.toPrecision` injects for large/small
12 * magnitudes (e.g. `(1500).toPrecision(2)` → `"1.5e+3"` would otherwise leak
13 * into fixed-notation output).
14 */
15export function roundToSignificant(value: number, n: number): number;
16export function roundToSignificant(value: BigDecimal, n: number): BigDecimal;
17export function roundToSignificant(
18 value: number | BigDecimal,
19 n: number
20): number | BigDecimal;
21export function roundToSignificant(
22 value: number | BigDecimal,
23 n: number
24): number | BigDecimal {
25 if (typeof value === 'number') {
26 if (!Number.isFinite(value)) return value;
27 return parseFloat(value.toPrecision(n));
28 }
29 return value.toPrecision(n);
30}
31
32/**
33 * Round a value to `k` digits after the decimal point (`toFixed` semantics),

Callers 1

fromDigitsFunction · 0.85

Calls 1

sliceMethod · 0.65

Tested by

no test coverage detected