You can use toFixed() to do that

var twoPlacedFloat = parseFloat(yourString).toFixed(2)
Answer from Mahesh Velaga on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseFloat
parseFloat() - JavaScript | MDN
The characters accepted by parseFloat() are plus sign (+), minus sign (- U+002D HYPHEN-MINUS), decimal digits (0 – 9), decimal point (.), exponent indicator (e or E), and the "Infinity" literal.
🌐
W3Schools
w3schools.com › jsref › jsref_parsefloat.asp
JavaScript parseFloat() Method
parseFloat("40.00"); parseFloat(" 40 "); parseFloat("40 years"); parseFloat("40H") parseFloat("H40"); Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
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...
🌐
Flexiple
flexiple.com › javascript › parsefloat-javascript
parseFloat JavaScript: Syntax and Examples - Flexiple
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › parseFloat
Number.parseFloat() - JavaScript | MDN
function circumference(r) { if (Number.isNaN(Number.parseFloat(r))) { return 0; } return parseFloat(r) * 2.0 * Math.PI; } console.log(circumference("4.567abcdefgh")); // Expected output: 28.695307297889173 console.log(circumference("abcdefgh")); // Expected output: 0
🌐
Copahost
copahost.com › home › javascript parsefloat: examples and variations of this function
Javascript parseFloat: Examples and variations of this function - Copahost
July 16, 2023 - It starts parsing the string from the beginning until it encounters a character that is not a part of a valid numeric value. This can include digits (0-9), a decimal point (.), or certain special characters like a positive (+) or negative (-) sign.
Find elsewhere
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Numbers
For converting values like 12pt and 100px to a number: Use parseInt/parseFloat for the “soft” conversion, which reads a number from a string and then returns the value they could read before the error.
🌐
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 ...
🌐
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
Top answer
1 of 2
1

Javascript has a type string and a type number, but does not have separate int and float types.

You can start with some strings:

> var intStr   = "446";
> var floatStr = "446.0";
> var decStr   = "446.";
> var floatVal = "446.7";

All of these have the type string

> typeof floatStr
"string"

Once you parse them using the Number object the result is of type number

> var n = Number.parseInt(intStr);
> n
446
> typeof n
"number"
> var f = Number.parseFloat(floatVal);
> f
446.7
> typeof f
"number"

So both parseInt and parseFloat produce a number.

Parsing a string with a zero 0 fractional value drops the fractional part, because 446.0 == 446

> Number.parseFloat(floatStr);
446

Following that, parsing a string that has a trailing decimal with no value is the same as a .0 value. 446.0 == 446. == 446

> Number.parseFloat(decStr);
446

If you want to keep the trailing decimal . you will have to maintain the variable as a string, and only convert it to a number when you are ready to perform computations with its value.

2 of 2
0

This is because (using your example) 44. is interpreted by Javascript as 44.0 which is the same as 44, which is what it then converts it to.

In JS, you do not have multiple data types for numbers - there are no ints, floats, etc, but instead there is number, a data type used to represent all numbers that can be interacted with in code. The difference between parseInt and parseFloat then is that parseInt strips the decimal values and parseFloat does not, however they both still return a number.

If I were making a calculator as you are, I would wait until the user had entered their full number before using parseInt or parseFloat on it. Assuming that the user is inputting into some sort of text input or DOM container, it will be a string anyway in the DOM, so there is no need to convert it to a number. Once you do come to processing the calculations, it won't matter if 44. is interpreted as 44, because that is in fact what it is.

You are probably receiving 446 rather than 44.6 because the decimal is not being inserted (parseFloat of decimal with nothing after it removes decimal, meaning the user is actually typing 446). Leave it as a string until the user finishes typing, then convert and the problem will be solved.

🌐
Techaltum
tutorial.techaltum.com › javascript-number.html
JavaScript Numbers | parseInt, parseFloat, and Number Methods Tutorial
parseFloat can also convert binary, octal and hexadecimal to decimal numbers. let a="100"; let b="100.5"; let c="100px"; let d="100.5px"; let e="abc100"; parseFloat(a) //100 parseFloat(b) //100.5 parseFloat(c) //100 parseFloat(d) //100.5 ...
🌐
W3cubDocs
docs.w3cub.com › javascript › global_objects › parsefloat.html
parseFloat - JavaScript - W3cubDocs
The characters accepted by parseFloat() are plus sign (+), minus sign (- U+002D HYPHEN-MINUS), decimal digits (0 – 9), decimal point (.), exponent indicator (e or E), and the "Infinity" literal.
🌐
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 - Finally, we can conclude by saying that parsing these float digits can be helpful for complex calculations, as even though the user enters any character, parseFloat restricts only numbers and takes only the number as an input, which is parsing and returns floating value. This javascript function is not vigorous as parseInt() function as it parses the incoming string values to floating-point numbers instead of decimal but can only work with base 10 decimal values, not octal or hexadecimal.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Attacomsian
attacomsian.com › blog › javascript-parse-float-two-decimal-places
Parse float with 2 decimal places in JavaScript
November 27, 2022 - It rounds the number and pads the decimal places with zero if necessary. Note that the toFixed() method returns a string representing the pointing point number. If you need a number, as a result, call the parseFloat() method again:
🌐
W3Schools
w3schools.com › jsref › jsref_tofixed.asp
JavaScript toFixed() Method
The toFixed() method rounds the string to a specified number of decimals.
🌐
DEV Community
dev.to › himanshudevgupta › 7-ways-to-convert-a-string-to-number-in-javascript-35pd
7 ways to convert a String to Number in JavaScript - DEV Community
February 21, 2023 - parseFloat("10"); // returns 10 parseFloat("10.33"); // returns 10.33 parseFloat("10 20 30"); // returns 10 parseFloat("10 years"); // returns 10 parseFloat("years 10"); // returns NaN · 5. Using Math.floor() The Math.floor() function returns the largest integer less than or equal to a given number. This can be little tricky with decimal numbers since it will return the value of the nearest integer as Number. str = '1222' console.log(Math.floor(str)) // returns 1222 a = 12.22 Math.floor(a) // expected result: 12 · 6. Multiply with number Multiplying the string value with the 1 which won’t change the value and also it will be converted to number by default.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
parseFloat question - JavaScript - The freeCodeCamp Forum
August 20, 2018 - I am trying to shorten the decimals when i am given the return of a number. I have two inputs that result in a number, but i am not sure how to implement it so it shorten the decimal points. For example 1.11111 becomes 1.11 I have tried to use Math.round as well but not having any luck $('.field5').val($('.field4').val() / $('.field3').val());