×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: petecocoon
Added: Sep 13, 2012 12:07 PM
Views: 172
It works also with comma separated float number and take 1 optional argument for truncating to a decimal position
"10,32424".parseFloat() => 10.32424
"10.32424".parseFloat() => 10.32424
"10,32424".parseFloat(2) => 10.32
"10.32424".parseFloat(2) => 10.32
  1.         String.prototype.parseFloat = function(decimal){
  2.                 var floatVal = parseFloat(this.replace(',', '.'));
  3.                 if (decimal){
  4.                         return Math.floor((Math.pow(10, decimal) * floatVal)) / Math.pow(10, decimal);         
  5.                 }
  6.                 return floatVal;
  7.         };