 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to deal with floating point number precision in JavaScript?
To handle floating point number precision in JavaScript, use the toPrecision() method. It helps to format a number to a length you can specify.
Example
<!DOCTYPE html> <html>    <body>       <script>          var num = 28.6754;          document.write(num.toPrecision(3));          document.write("<br>"+num.toPrecision(2));          document.write("<br>"+num.toPrecision(5));       </script>    </body> </html>  Output
28.7 29 28.675
Advertisements
 