How can I turn string type to the integer type in JavaScript

I have a variable, let's say const num1 = "5555"; or const num1 = "5555.55"

I need to turn it to decimal number.'So output should be type number 5555.00 or 5555.55

What I have tried is parseFloat(num1).toFixed(2) Which always gives me "5555.00" or "5555.55"

I tried to use Number(parseFloat(num1).toFixed(2)) Which gave me 5555 and 5555.55 both type number.

How can I convert type string "5555.55" to type number 5555.55?

Read more here:

Content Attribution

This content was originally published by darkseid at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: