Explaining the meme
Internet is made of millions of memes flowing everyday, so, devs create a ton of new images showing how their code doesn’t work,
the server is down or even the programming language is broken or annoying. ?
So someone discovered that using the default parseInt(); function with a number 0.0000005 returns the 5 as result instead of 0.
Ok, but how is that even possible? ?
Python uses int() to parse so I use it here. But I realized that the function is protected
against using a float as an input, showing the following error.
Maybe this is not that simple.
Okay so python is protected. But I solve this issue using float() function and now is running:
The output is showing, but using scientific notation
Getting closer to the solution ?
Excellent! The number is shown in the correct way now. BUT IN SCIENTIFIC NOTATION
returns 5e-7 and then getting the first numbers before the ‘ilegal characters’
We can see this behaivour here with the following snipet:
The conclusion ?
You MUST be using parseFloat() and then trunc the number if you want.
So using the right tools to do the right things, that’s the key.
and the security of the variable types.
So I tried using parseInt() with the float inside… and typescript throw a compilation error!
How amazing is that?
I hope you enjoy this experiment!?