Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript display the last 3 numbers after the dot fixed(3) not working

I have a number which looks number this:

800.60000305176541

This number changes all the time.

So I’m doing this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading