cultureinfo - Culture sensitive ParseFloat Function in JavaScript? -
do have suggestion writing culture sensitive parsefloat function in javascript, when have string 100,000.22 in culture format parse float function returns 100000.22 whereas if enter 100.000,22 in swedish culture returns 100000.22 in float?
i've improved mwilcox' function handle values withous separators.
function parsefloatopts (str) { if(typeof str === "number"){ return str; } var ar = str.split(/\.|,/); var value = ''; (var in ar) { if (i>0 && i==ar.length-1) { value += "."; } value +=ar[i]; } return number(value); }
Comments
Post a Comment