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.
{ price: '38.50', qty: 2, discount: 'none' }{
total: {
$mul: [
{ $toNumber: { value: { $ref: '$.price' } } },
{ $toNumber: { value: { $ref: '$.qty' } } },
],
},
discount: {
$toNumber: { value: { $ref: '$.discount' }, fallback: 0 },
},
}{ total: 77, discount: 0 }Runs in this page on the installed package. The input and the expected output are defined by the example.