Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript: parseFloat: Convert string to float

parseFloat(string)
parseFloat takes a string and return a float value.

Ex:
var a = parseFloat("123.45"); // Return 123.45
var b = parseFloat("0.987654"); // Return 0.987654

parseFloat converts the Character by character, if it is unable to convert any character it ignores it and all succeeding characters and returns the float value parsed up to that point.

var c = parseFloat("123.45awq34"); // Return 123.45

If the first character cannot be converted to a number, parseFloat returns NaN.

var d = parseFloat("a1234"); // Return NaN

parseFloat.html





parseFloat



"text/javascript">
var a = parseFloat("123.45"); // Return 123.45
var b = parseFloat("0.987654"); // Return 0.987654
var c = parseFloat("123.45awq34"); // Return 123.45
var d = parseFloat("a1234"); // Return NaN

document.write("a = " + a + "
"
);
document.write("b = " + b + "
"
);
document.write("c = " + c + "
"
);
document.write("d = " + d + "
"
);







Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

JavaScript: parseFloat: Convert string to float

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×