Phaser API Documentation

  Version: 

Member of: Phaser.Math

<static> RoundTo(value, [place], [base])

Description:

Round a value to the given precision.

For example:

RoundTo(123.456, 0) = 123
RoundTo(123.456, 1) = 120
RoundTo(123.456, 2) = 100

To round the decimal, i.e. to round to precision, pass in a negative place:

RoundTo(123.456789, 0) = 123
RoundTo(123.456789, -1) = 123.5
RoundTo(123.456789, -2) = 123.46
RoundTo(123.456789, -3) = 123.457

Parameters:

name type arguments Default description
value number

The value to round.

place number <optional> 0

The place to round to. Positive to round the units, negative to round the decimal.

base number <optional> 10

The base to round in. Default is 10 for decimal.

Returns:
Description:

The rounded value.

Type:
  • number
Since: 3.0.0
Source: src/math/RoundTo.js (Line 7)