1

Possible Duplicate:
Is JavaScript's Math broken?

I have two variables

var first : float = 200;
var next : float;
next = first * 1.2;

and when i write in debug log "next" it gives 40,00002. any advices?

Community
  • 1
  • 1
Damian Bala
  • 55
  • 1
  • 1
  • 7

2 Answers2

2

The precision of floating point computations is only as precise as the precision (no of bits and mantissa) it uses. http://en.wikipedia.org/wiki/Floating_point#Machine_precision_and_backward_error_analysis

clyfe
  • 23,695
  • 8
  • 85
  • 109
  • 1
    also see http://stackoverflow.com/questions/1458633/elegant-workaround-for-javascript-floating-point-number-problem – clyfe Apr 20 '12 at 09:30
2

This give you 240. I think your are not not following the standard. I even parsed it with float

var first =parseFloat(200.0);
var next ;
next = parseFloat(first * 1.2);
alert(next);

Adil
  • 146,340
  • 25
  • 209
  • 204