How do I round off the decimal values to two digits
This example demonstrates rounding off the decimal values to two digits.
In the solution shown below, the decimal value of the Amount "120.4682" is rounded off to two digits i.e, "120.47" using "toFixed(<digit>)" javascript method in "storeEval" command and stored into a variable.
Solution:
# | Command | Target | Value |
---|---|---|---|
Rounding off the decimal value to two digits | |||
1 | storeEval | function f(){var Amount=120.4682.toFixed(2); return Amount;}f(); |
Amount |
Tips, Tricks, Gotchas & Best Practices:
- As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscores.