I have a number which looks number this:
800.60000305176541
This number changes all the time.
So I'm doing this:
var mynumber = 800.60000305176541
var changenumber = mynumber.toFixed(3);
This is displaying 800.600
... I need it to display the last 3 like:
800.541
How can I do this?
CodePudding user response:
You can convert to string and do your manipulations. Please note we are loosing the right most digit due to limits of javascript.
var num = 800.60000305176541;
var str = "" num
var arr = str.split(".");
var result = arr[0]
if (arr[1]) {
result = "." arr[1].slice(-3)
}
console.log(num)
console.log(result)
CodePudding user response:
You could also try to solve it mathematically.
800.60000305176541
800.60000305176000 -
------------------
800.00000000000541
.00000000000541
10^10. X
------------------
0,541 800 = 800.541