Level 75
If parsing, wouldn't you want a 0 rather. You could use a ternary to return 0 if the text is empty.
2 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
<input type="text" onchange="(function(el){el.value=parseFloat(el.value).toFixed(2);})(this)">
How to return empty string or empty value instead NaN after onchange event ?
Please or to participate in this conversation.