## Lazy Number manipulation (such as decimal places or precision)

14 October 2009

If you want to manipulate a Number Object (variable) to a specific precision or to fixed decimal places, instead of manipulating the Number itself you can use the Number Class conversion Methods such as toFixed and toPrecision and cast the String Objects they return back to Number Objects:

pi = Number(Math.PI.toFixed(2));

trace(pi); // 3.14

Not a replacement for a dedicated rounding function for mathematical formulae, but a handy shortcut to output rounded Numbers in a DataProvider for example.

p.s. Math.round rounds to Integer Objects, as do Math.floor and Math.ceil which is why this can be useful

## 16 Comments