I'm working on a calculator app. Everything is running fine but it runs into problem when I try to compute difference between to numbers with decimal. The issue is coming from method I used to convert string into number. e.g. parseFloat("0.584") - parseFloat("0.94801") -0.36401000000000006
Ideally the output should be -0.36401 but there unnecessary zeros with a 6 at the end.
As a temp fix I've used toFixed(5) in the end. (parseFloat("0.584") - parseFloat("0.94801")).toFixed(5) '-0.36401' But that limits my calculator to be precise up to 5 decimal places
Is there a better way to convert strings into float with better precision?