0

When I try to calculate a simple float value, I get the wrong result:

var a = 0.1111;
var b = 1 * 100;
alert(b); // Returns 11.110000000000001

Why it happens is discussed at Is floating point math broken?, but how can you get around this problem in javacript?

https://jsfiddle.net/Lc0805mt/1/

Community
  • 1
  • 1
einord
  • 2,278
  • 2
  • 20
  • 26

1 Answers1

1

This help you :

<html>
<head>
</head>
    <body>
       <script>
           var a = 0.1111;
           var b = ((a*10000)*100)/10000;
           alert(b);
        </script>
    </body>
</html>
Ehsan
  • 12,655
  • 3
  • 25
  • 44