3

Which type of variable should I use in order to calculate double values without floating points?

i.e. let x = 0.6;

I want x*3/4 to be calculated as 0.45 instead of 0.44999999999999996.

talha06
  • 6,206
  • 21
  • 92
  • 147
  • 1
    [What Every Computer Scientist Should Know About Floating-Point Arithmetic](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) – Darin Dimitrov Dec 28 '15 at 14:08
  • http://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript – yas Dec 28 '15 at 14:08

1 Answers1

3

There is only one type of number in Javascript... Number :)

You might try something like .toFixed()

(0.6 * 3/4).toFixed(2) => 0.45

Mark
  • 12,359
  • 5
  • 21
  • 37