How to round the factorial value in java scripts if we have below value
7.156945704626378 e +118
I want 7.16 only please let me know if we have any solution?
How to round the factorial value in java scripts if we have below value
7.156945704626378 e +118
I want 7.16 only please let me know if we have any solution?
Put it in a String variable:
var x = "7.156945704626378e+118";
Then use a regular expresion which checks for the part before e and parse it back to float:
var y = parseFloat(x.match(/\d+[.][0-9]+/)[0]);
And round to 2 decimal points by:
var z = y.toFixed(2);
If you still want your e118 just multiply z with 1e118 then.
((Number(7.156945704626378e+118))/1.0e+118).toFixed(2);
try this
you can refer links
Formatting a number with exactly two decimals in JavaScript
and
How to convert a String containing Scientific Notation to correct Javascript number format
var number=7.1569;
number*=100;
var new_number = Math.round(number);
new_number/=100;
I am not sure whether this approach is correct but this give what user want in question.
Number((+num.toString().replace(/e.*/, '')).toFixed(2))
DEMO
var num = 7.156945704626378e+118;
console.log(Number((+num.toString().replace(/e.*/, '')).toFixed(2)));
# 7.16
Note:
This assumes that exponent is not significant and mantissa
is what all required for rounding off.