Internally Integers and Floats are stored differently.
This is how integers are stored depending upon the machine the number of bits will be different. ( Normally it will be 32 or 64 bit)
By default most of the modern languages save a float/double
as double precision( 64 Bit) But for this blog I will show you a 32 bit model! For the same value 20 but 20.0 will be saved in the IEEE754 Double Precision Format.
This is because we can save integers easily in the binary form but not floats. Floats are special numbers and always require special care when dealing them especially if you're using them for calculations. This talks about Floats and Binary
We can see there are some errors during the conversion of this float to binary. This is why we get this title.
We had this problem when we were developing a payment page as the input should be number.
The simplest solution is to use regex pattern for number and input type = "text"
. Peace 🕊
If you want to receive these blogs in your mail from @Medium. Subscribe to my blogs