
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Parse Float with Two Decimal Places in JavaScript
To parse float with two decimal places, use the concept of toFixed(2). Following is the code −
Example
var price = 178932.89; var tax = 7.9; var totalPrice = price*tax; console.log("The actual value="+totalPrice); var gettingTwoPlacedValues = parseFloat(totalPrice).toFixed(2); console.log("After getting two placed values="+gettingTwoPlacedValues);
To run the above program, you need to use the following command −
node fileName.js.
Output
Here, my file name is demo142.js. This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo142.js The actual value=1413569.8310000002 After getting two placed values=1413569.83
Advertisements