Today, I found one of weird problem in my project about using parseFloat() function of Javascript. The usage of parseFloat() function parses a string and returns a floating point number.
example usage of parseFloat()
2<!--- return value is "10.33" --->
3
4document.write(parseFloat("I AM PPSHEIN"));
5<!--- return value is "NaN" --->
It's still fine to use parseFloat() for parsing decimal value. If our decimal value is like "1,923.50", do you know the return value of this number after parsing with parseFloat().
Return value will be like as follow:
2<!--- return value is "1" --->
At that time, we need to skip COMMA (",") from this value first and use parseFloat() after that. That's why I need to create skipping comma function in javascript as follow.
2 NumberString = NumberString.replace(/,/g,"");
3 NumberString = NumberString.replace(/\s/g,"");
4 return NumberString;
5}
After that, we can use parseFloat() function as follow.
2<!--- return value is "1,923.50" --->

Android
Top of Page
#1 by Dan G. Switzer, II on 7/29/11 - 8:48 AM
If you don't specify the base 10, then parseFloat() tries to auto-detect the radixand that may cause you problems with certainly input values.
See this link for more info:
http://jibbering.com/faq/notes/type-conversion/#tc...
#2 by ppshein on 7/29/11 - 8:54 AM
#3 by dotNetFollower on 9/22/11 - 4:52 PM
Very nice article. I used it to write a logically related post in my blog - http://dotnetfollower.com/wordpress/2011/09/javasc.... Thank you!
#4 by ppshein on 9/22/11 - 8:16 PM
#5 by Steve on 11/4/11 - 9:55 AM
if (typeof(superParseFloat) == "undefined") {
superParseFloat=parseFloat;
}
parseFloat=function(x) {
if ( x ) {
while(x.indexOf(",")>-1)
x = x.replace(",","");
} else {
x=0;
}
return(superParseFloat(x));
}
#6 by ppshein on 11/4/11 - 10:35 AM