roundDecimal

Rounds a number to a certain number of decimal places.

This can be useful when comparing two doubles, since floating point operations tend to cause small amounts of drift.

For example, (3.222).roundDecimal(1) == 3.2. We're truncating to the 1st decimal place, rounding the rest down. On the other hand, (0.9999).roundDecimal(3) == 1.0 because the 4th 9 rounds up.