You can use toFixed() to do that

var twoPlacedFloat = parseFloat(yourString).toFixed(2)
Answer from Mahesh Velaga on Stack Overflow
🌐
Attacomsian
attacomsian.com › blog › javascript-parse-float-two-decimal-places
Parse float with 2 decimal places in JavaScript
November 27, 2022 - Use the toFixed() method to format the floating point number to 2 decimal places. The toFixed() method takes a number as input and returns a string representation of the number formatted to 2 decimal places.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-parse-float-with-two-decimal-places-in-javascript
How to Parse Float with Two Decimal Places in JavaScript? - GeeksforGeeks
Below are the approaches to parse ... the string isn't numeric, it returns NaN. To limit the number to two decimal places, use toFixed(2), which rounds the result....
Published   July 23, 2025
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseFloat
parseFloat() - JavaScript | MDN
The parseFloat() function parses a string argument and returns a floating point number. function circumference(r) { return parseFloat(r) * 2.0 * Math.PI; } console.log(circumference(4.567)); // Expected output: 28.695307297889173 console.log(circumference("4.567abcdefgh")); // Expected output: ...
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript string to float 2 decimal | example code
JavaScript string to float 2 decimal | Example code
June 29, 2022 - Simple example code parse float with two decimal places. When you use toFixed, it always returns the value as a string. This sometimes complicates the code. <!doctype html> <head> <script> var str = "100.999"; var res = parseFloat(str).toFixed(2) console.log(res); </script> </head> <body> </body> </html>
🌐
Medium
frontendinterviewquestions.medium.com › how-to-float-number-with-2-decimal-places-in-javascript-d3a9650c422c
How to float number with 2 decimal places in JavaScript ? | by Pravin M | Medium
October 31, 2024 - JavaScript provides several ways to format numbers. Here are the most common methods: ... The toFixed() method converts a number into a string representation, keeping a specified number of decimals.
🌐
Three.js
discourse.threejs.org › discussion
🙊 Change floating-point to 2 decimal places? - Discussion - three.js forum
Before I go down this rabbit hole further. If you could share your wisdom/experience. I’m assuming with certain large floating-point numbers is a known problem and CAN NOT be converted to 2 decimal places. As these large numbers appear to be an error, it is the way things work with my current ...
Published   July 24, 2018
🌐
IncludeHelp
includehelp.com › code-snippets › how-to-parse-float-with-two-decimal-places-in-javascript.aspx
How to parse float with two decimal places in JavaScript?
// Float value as string const str = "123.456"; // Parsing to float with two decimal digits var result = parseFloat(str).toFixed(2); // Printing result console.log("Float with two decimal digits: ", result);
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › how-to-parse-float-with-two-decimal-places-in-javascript
How to 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 ac
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript | MDN
The toFixed() method of Number values returns a string representing this number using fixed-point notation with the specified number of decimal places. function financial(x) { return Number.parseFloat(x).toFixed(2); } console.log(financial(123.456)); // Expected output: "123.46" console.lo...
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-parse-float-with-two-decimal-places-in-typescript
How to Parse Float with Two Decimal Places in TypeScript ? - GeeksforGeeks
July 23, 2025 - Example: The below example uses the Number constructor and toFixed method to convert the number 123.45678 into a string with two decimal places and then parses it back to a floating-point number (123.46).
🌐
W3Schools
w3schools.com › jsref › jsref_parsefloat.asp
JavaScript parseFloat() Method
The parseFloat() method parses a value as a string and returns the first number.
🌐
Stack Overflow
stackoverflow.com › questions › 27061322 › convert-string-to-float-up-to-2-decimal-places
javascript - Convert String to Float up to 2 Decimal places - Stack Overflow
then use var float = parseFloat(newFloat); (because toFixed() returns string) to convert to float again. ... and than you end up with the variable float being this: 1.1 instead of 1.10. You are still wrong 2014-11-21T12:44:14.13Z+00:00
🌐
W3Schools
w3schools.com › jsref › jsref_tofixed.asp
JavaScript toFixed() Method
❮ Previous JavaScript Number Reference Next ❯ · let num = 5.56789; let n = num.toFixed(); Try it Yourself » · let num = 5.56789; let n = num.toFixed(2); Try it Yourself » · More examples below · The toFixed() method converts a number ...
🌐
Flexiple
flexiple.com › javascript › parsefloat-javascript
parseFloat JavaScript: Syntax and Examples - Flexiple
Return value: It returns a floating-point Number and if the first character of a string cannot be converted to a number then the function returns NaN i.e, >not a number. function myFunction() { parseFloat("9") Output: 9 parseFloat("11.00") Output: 9 parseFloat("10.89") Output: 10.89 parseFloat("10 20 30") Output: 10 parseFloat(" 100 ") Output: 100 parseFloat("1 xyz") Output: 1 parseFloat("xyz 1") Output: NaN } If parseFloat encounters a character other than a plus(+), minus (-), numerals (0–9), decimal (.), or exponent (e or E), it returns the value up to that character, ignoring the invalid character and characters following it.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-format-number-to-two-decimal-places
Format a number to 2 Decimal places in JavaScript | bobbyhadz
The parseFloat() function parses a string to a floating-point number. ... Copied!console.log(parseFloat('6.178')); // 👉️ 6.178 console.log(typeof parseFloat('6.178')); // 👉️ number · You can define a reusable function that takes care ...