I want to extract decimal number 265.12 or 0.0 from alphanumeric string (say amount) having value $265.12+ or $265.12- or
A more elegant solution and also a method to avoid the 0.7700000004 javascript math do this:
var num = 15.3354;
Number(String(num).substr(String(num).indexOf('.')+1));
The result will always be the exact number of decimals. Also a prototype for easier use
Number.prototype.getDecimals = function () {
return Number(String(this).substr(String(this).indexOf('.')+1));
}
so now just 15.6655.getDecimals() ==> 6655