Back

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

I'd like to round at most 2 decimal places, but only if necessary.

Input:

10 1.7777777 9.1

Output:

10 1.78 9.1

How can I do this in JavaScript?

1 Answer

0 votes
by (106k points)
edited by

To round of till 2 decimal places, you can use the following piece of code:-

Math.round(num * 100) / 100

If you are passionate to pursue a career in Web Development, you can take up Web Development Online Courses by Intellipaat! 

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 9, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Oct 17, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Oct 9, 2019 in Java by Anvi (10.2k points)

Browse Categories

...