3 ms·
My code review comment on this would be... Don't be "clever". Use parseInt or parseFloat.
by itslennysfault 9y ago
My code review comment on this would be...
Don't be "clever". Use parseInt or parseFloat.
- tobr 9y agoThat’s a terrible idea: parseInt(0.000001) // 0 parseInt(0.0000001) // 1
- jannes 9y agoFor anyone who is wondering why: parseInt() only accepts strings as input. So JavaScript calls .toString() on the number before passing it as an argument. (0.000001).toString() // "0.000001" (0.0000001).toString() // "1e-7" By the way, TypeScript or Flow would have caught this error during compile time.
- jannes 9y agoparseInt() and parseFloat() are made for strings, not for numbers. I think you are looking for one of these: Math.round() Math.ceil() Math.floor()