@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
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¼"