Skip to content

This site describes solve-engine 2.44.0, the version npm installs.

formatValue

function formatValue(value, settings?): string;

Defined in: packages/engine/src/format/FormatEngine.ts:1332

Render an evaluated Value as a display string, dispatching on value.type to the type-specific formatter (number, hex, datetime, unit of measurement, matrix, range, percentage, …).

Most branches produce a "= "-prefixed result string (matching the plugin’s inline-result convention); ValueType.Error is the one exception, it returns the human-readable error message directly (stored in value.unit), not an "= "-prefixed string.

ParameterTypeDescription
valueValueThe evaluated value to format.
settings?FormattingOverridesLocale/precision/separator options; defaults to DEFAULT_FORMATTING_SETTINGS when omitted. A partial object names only what it changes and is merged over the defaults group by group ({ calendar }, { numberResult: { decimalSeparatorLocale: "de-DE" } }); a complete one is used as it is. To format with an engine’s own calendar and locale, ExpressionEngine.formatValue is the shorter call.

string

const value = engine.evaluateExpression("10 USD to GBP");
formatValue(value); // "= £7.85" (exact output depends on live exchange rates)