⚠️ This is pre-release documentation for v3. For stable docs, visit v2.
Skip to content

@tmlmt/cooklang-parser / formatNumericValue

Function: formatNumericValue()

formatNumericValue(value, useVulgar?): string

Format a numeric value (decimal or fraction) to a string.

Parameters

value

DecimalValue | FractionValue

The decimal or fraction value to format

useVulgar?

boolean = true

Whether to use Unicode vulgar fraction characters (default: true)

Returns

string

The formatted string representation

Example

typescript
formatNumericValue({ type: "decimal", decimal: 1.5 }); // "1.5"
formatNumericValue({ type: "fraction", num: 1, den: 2 }); // "½"
formatNumericValue({ type: "fraction", num: 1, den: 2 }, false); // "1/2"
formatNumericValue({ type: "fraction", num: 5, den: 4 }, true); // "1¼"