val = "2.";
var num = parseFloat(val).toFixed(2);
I'm using the parseFloat to turn the string into a number. Then I'm using toFixed(2) to make sure 2 zeros will be added after the decimal point. My problem is if val
has a comma this gets all screwed up.
Example:
val = "2,234.";
var num = parseFloat(val).toFixed(2);
The output is 2.00
.
How can I allow for the 00
to be added and the comma not to be replaced?
Val is a string to start with sorry about the confusion. it should end up outputting 2,234.00 and the first val should output 2.00