Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

when converting from a float to a string, how can I get just 2 digits after the decimal point? For example, 5.56 instead of 5.56789.

1 Answer

0 votes
by (13.1k points)

You can use toFixed() function to get the required number of digits after the “.”. Here is an example of this:

function myFunction() {

  var num = 5.56789;

  var n = num.toFixed(2);

  console.log(n);

}

This would give you an output: 5.56

Interested in full stack development? Check out the full stack developer course from Intellipaat.

Related questions

0 votes
1 answer
asked Aug 13, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Apr 4, 2021 in Java by dante07 (13.1k points)
–1 vote
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...