Java Reference
In-Depth Information
Put a space before the dot:
5 .toExponential(); >> "5e+0"
Always write integers as a decimal:
5.0.toExponential(); >> "5e+0"
Place the integer in parentheses:
(5).toExponential(); >> "5e+0"
Assign the number to a variable:
var number = 5;
>> 5
number.toExponential();
>> "5e+0"
The toFixed() method rounds a number to a fixed number of decimal places:
var pi = 3.1415926;
<< undefined
pi.toFixed(3); // only one dot needed when using variables
<< "3.142"
Note that the value is returned as a string.
The toPrecision() method rounds a number to a fixed number of significant figures
that is once again returned as a string (and often using exponential notation):
325678..toPrecision(2);
<< "3.3e+5"
2.459.toPrecision(2);
<< "2.5"
Search WWH ::




Custom Search