Jquery - No rounding number

Asked

Viewed 428 times

-1

How can I leave the result of an account with the entire result, unfurnished, ie every time jQuery executes the script it returns a value and each browser rounds in its own way.

I want a way to leave the integer value without rounding for all browsers as in the example:

This is the real value:

933 / 9 = 103.66666666666666666666666666667

In the browser:

933 / 9 = 103.766

  • 2

    Won’t be 103.667 in the browser? E 103.666...7 is not the actual value!!!

2 answers

0

One option would be to force the number of decimals with toFixed:

var num = (933 / 9).toFixed(20); // 103.66666666666667140362
  • That way limit the characters to 20, I want a form that has no limit.

  • 2

    No limit exists even on paper! It is an infinite tithe https://pt.wikipedia.org/wiki/D%C3%Adzima_peri%C3%B3dica

0

Ever tried to use parseFloat () ?

var num = parseFloat(933 / 9);

console.log (num) // 103.66666666666667

Or you can use as Luke C. said but with maximum value, so:

var num = (933 / 9).toFixed(100);
console.log (num); // 103.6666666666666714036182384006679058074951171875000000000000000000000000000000000000000000000000000000

Using maximum function value toFixed (0 to 100).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.