You can use toFixed() to do that

var twoPlacedFloat = parseFloat(yourString).toFixed(2)
Answer from Mahesh Velaga on Stack Overflow
🌐
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
It slices the string up to the desired decimal precision and then converts it back to a number. ... function ParseFloat(str,val) { str = str.toString(); str = str.slice(0, (str.indexOf(".")) + val + 1); return Number(str); } console.log(Par...
Published: July 23, 2025
Discussions

JavaScript - parseFloat force 2 decimals as NUMBER - Stack Overflow
I realize this has been asked in some shape or form plenty of times, but every answer I've read so far says use .toFixed(2), unfortunately, that returns the result as a String. Some people suggested More on stackoverflow.com
🌐 stackoverflow.com
javascript - Parse to float with 2 decimal places - Stack Overflow
I need to round a value with 2 decimal places that I receive from a web service. To do this i use this methods toFixed and parseFloat because I need the final value in a float. However when I have ... More on stackoverflow.com
🌐 stackoverflow.com
floating point - JavaScript displaying a float to 2 decimal places - Stack Overflow
I wanted to display a number to 2 decimal places. I thought I could use toPrecision(2) in JavaScript . However, if the number is 0.05, I get 0.0500. I'd rather it stay the same. See it on JSbin.... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to round to at most 2 decimal places, if necessary - Stack Overflow
I'd like to round at most two 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? More on stackoverflow.com
🌐 stackoverflow.com
🌐
Attacomsian
attacomsian.com › blog › javascript-parse-float-two-decimal-places
Parse float with 2 decimal places in JavaScript
November 27, 2022 - The toFixed() method takes a number as input and returns a string representation of the number formatted to 2 decimal places. const str1 = '2.567' const res1 = parseFloat(str1).toFixed(2) console.log(res1) // 2.57 const str2 = '5' const res2 ...
🌐
Sabe
sabe.io › blog › javascript-parse-float-two-decimal-places
How to Parse Float to 2 Decimal Places in JavaScript - Sabe.io
August 23, 2022 - JAVASCRIPTconst string = "123.456"; const parseToTwoDecimalPlaces = (string) => { const fixedString = parseFloat(string).toFixed(2); return parseFloat(fixedString); } const number = parseToTwoDecimalPlaces(string); console.log(number); console.log(typeof number); BASH123.46 number · And there you have your two decimal places number!
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseFloat
parseFloat() - JavaScript - MDN Web Docs
Note: JavaScript does not have ... would return the same value: a Number 42. The parseFloat function converts its first argument to a string, parses that string as a decimal number literal, then returns a number or NaN....
🌐
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);
🌐
TutorialsPoint
tutorialspoint.com › article › 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 − · var price = 178932.89; var tax = 7.9; var totalPrice = price*tax; console.log("The actual value="+totalPrice); var gettingTwoPlacedValues = ...
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-format-number-to-two-decimal-places
Format a number to 2 Decimal places in JavaScript | bobbyhadz
The toFixed method takes a parameter, representing how many digits should appear after the decimal and returns the result. ... Copied!const num1 = 13.505; const result1 = num1.toFixed(2); console.log(result1); // 👉️ 13.51 // ----------...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-parse-float-with-two-decimal-places-in-typescript
How to Parse Float with Two Decimal Places in TypeScript ? - GeeksforGeeks
April 28, 2025 - Example: The below example uses bitwise OR operations to round the number 123.45678 to two decimal places, resulting in 123.45. ... const input: number = 123.45678; const output: number = ((input * 100) | 0) / 100; console.log(output); ... JavaScript provides an inbuilt parseFloat() method to parse a string and returns a floating-point number.
🌐
Copahost
copahost.com › home › javascript parsefloat: examples and variations of this function
Javascript parseFloat: Examples and variations of this function - Copahost
July 16, 2023 - We have to pass a number in the toFixed method and the resulting integer will have that many numbers of digits after the decimal. The following example shows how to use the toFixed method with the parseFloat.
🌐
MSR
rajamsr.com › home › javascript parsefloat(): how to avoid common mistakes
JavaScript ParseFloat(): How to Avoid Common Mistakes | MSR - Web Dev Simplified
January 28, 2024 - One way to address this issue is using the JavaScript toFixed() function. let value1 = parseFloat("0.1"); let value2 = parseFloat("0.2"); let sum = value1 + value2; // sum is 0.3000000000000000444089209850062616169452667236328125 let sumString ...
🌐
YouTube
youtube.com › watch
How to Format Numbers with toFixed() and parseFloat() in JavaScript | Round and Convert Values in JS - YouTube
Want to format numbers in JavaScript to 2 decimal places or convert strings to numbers? In this beginner-friendly tutorial, you’ll learn how to use toFixed()...
Published: July 6, 2025
🌐
W3Schools
w3schools.com › jsref › jsref_parsefloat.asp
JavaScript parseFloat() Method
The parseFloat() method parses a value as a string and returns the first number.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › parsefloat in javascript
parseFloat in JavaScript | 10 Useful Examples of parseFloat in JavaScript
March 23, 2023 - If there are two decimals, the second decimal is invalid and the parseFloat() method converts string up to that position. String 22.45.32 will be parsed to 22.45. ... <!DOCTYPE html> <html> <head> <script> document.write(parseFloat( "22.45.32" ...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript - MDN Web Docs
The toFixed() method returns a string representation of a number without using exponential notation and with exactly digits digits after the decimal point.
🌐
CoreUI
coreui.io › blog › how-to-round-a-number-to-two-decimal-places-in-javascript
How to round a number to two decimal places in JavaScript · CoreUI
February 21, 2024 - The toFixed() method is a simple way to round numbers to a specified number of decimal places, returning the result as a string. const number = 4.687 const rounded = number.toFixed(2) console.log(rounded) // Outputs: 4.69 · Note: Since toFixed() ...