-2

I am using javascript to calculate a basket total for a simple html5 application. But javascript giving me wrong result in mobile and pc side.

Tested in Safari and Chrome in Mac and Chrome in Android.

For example: 9.1*9= 81.89999999999999 11.1*9= 99.89999999999999

What can i do :D

ersin ceylan
  • 107
  • 1
  • 6

1 Answers1

0

Using Number.tofixed(n)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

(9.1 * 9).toFixed(2) = "81.90"
auronsan zenx
  • 57
  • 1
  • 4