parseFloat(1.51e-6);
// returns 0.00000151
parseFloat(1.23e-7);
// returns 1.23e-7
// required 0.000000123
I am sorting table columns containing a
You can use toFixed()
instead of parseFloat()
to format the numbers the way you want.
For example (1.23e-7).toFixed(9)
will render as 0.000000123
To be able to sort these with sorts default string comparison, make sure to prefix all of them with zeroes and make them all the same size so the decimal dots wil line up.
You can extend the string object with padLeft like this:
String.prototype.padLeft = function(len, char){
var prefix = '';
var length=this.length;
if(len>length)
for(var i=0;i < len-length;i++) prefix += char;
return prefix + this;
}
Now you can call ((1.23e-7).toFixed(9)).padLeft(15,'0')