How to Stop parseFloat From Accepting Garbage

parseFloat accepts partial input and hides bugs.

#javascript #parsefloat #parsing #bug #howto #validation

https://www.youtube.com/watch?v=GSypdxVeB-0

How to Stop parseFloat From Accepting Garbage #validation

YouTube

#JavaScript For the umpteenth time I hate string to number conversion. Given an input for a number like

3
3.1
-0.314e2
314e-2

but **NOT**

314e-2nowIhitthekeyboardwithmyforehead

and **not** the empty string, which is not a number.🤬 Leading and trailing space? Well, OK. At most.

Number(cruft) => empty string is 0
parseFloat() => allows trailing cruft

Solutions found: regexp+parseFloat or compare with back-conversion.

Really? Am I missing a modern api?

#parseFloat #number #webdev