⚠️ 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

The decimal or fraction value to format

DecimalValue | FractionValue

useVulgar?

boolean = true

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

Returns

string

The formatted string representation

Example

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