Example
Type a price however you like, with a currency symbol, commas, spaces and the stored value is a
clean number.
<div b-context="demo.dataFormatter">
<input type="text" placeholder="$0.00" b-bind="price" b-data-formatter="parsePrice" />
<p>Stored value: <b b-value="price"></b></p>
</div>
$bindary.appData.demo.dataFormatter = { price: 0 };
ctrl.parsePrice = (templateItem, element, value) =>
{
const parsed = parseFloat(value.replace(/[^0-9.]/g, ''));
return isNaN(parsed) ? 0 : parsed; // always a real number, never undefined
};
Result
Type $1,234.56 and tab away: the field keeps what you typed, but
price holds 1234.56, a real number, ready for anything that expects
one.