Prism · Math

$toNumber

A number from a number or from numeric text, as a form, a CSV or an API often sends it. Anything else refuses with E_TYPE, unless fallback says what to answer.

The source
{ price: '38.50', qty: 2, discount: 'none' }
The config
{
  total: {
    $mul: [
      { $toNumber: { value: { $ref: '$.price' } } },
      { $toNumber: { value: { $ref: '$.qty' } } },
    ],
  },
  discount: {
    $toNumber: { value: { $ref: '$.discount' }, fallback: 0 },
  },
}
What comes out
{ total: 77, discount: 0 }
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.