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?
Advertisement
Answer
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)