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

How I convert a number to 3 decimal points?

I’m having a problem where I can’t convert numbers to something like "0.037", given the case where I have 37 as one of these numbers, without this affecting larger numbers like "2015", which in turn manage to become "2.015".

I tried approaches like:

myNumber = parseFloat(myNumber.toFixed(3));
myNumber = (myNumber / 1000).toFixed(3);

i keep having my whole number the same "37" not "0.037"

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

The most efficient approach to the case so far has been parseFloat with toFixed, however, as stated, it only works on numbers that are larger, not integers like "0" and "37".

>Solution :

its just a simple syntax error, you need to chain operations in JS like this:

let myNumber = parseFloat(yourNumberHere).toFixed(3);

or like this :

let myNumber = parseFloat(your number);
myNumber.toFixed(3);
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