How to add floating point numbers in javascrtipt?

Prob­lem

0.1 + 0.2 == 0.3 // false

Rea­son

0.1 + 0.2 // 0.30000000000000004

Solu­tion

parseFloat( (0.1 + 0.2).toFixed(1) ) == 0.3 // true

You may also like...