Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Enums](https://developer.android.com/reference/java/math/RoundingMode#enumconstants) \| [Methods](https://developer.android.com/reference/java/math/RoundingMode#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/math/RoundingMode#inhmethods)

# RoundingMode


`
public

final

enum
RoundingMode
`


`


`

`

extends https://developer.android.com/reference/java/lang/Enum<https://developer.android.com/reference/java/math/RoundingMode>


`

`


`

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.lang.Enum](https://developer.android.com/reference/java/lang/Enum)\<[java.math.RoundingMode](https://developer.android.com/reference/java/math/RoundingMode)\> ||
|   | ↳ | java.math.RoundingMode |

<br />

*** ** * ** ***

Specifies a *rounding policy* for numerical operations capable
of discarding precision. Each rounding mode indicates how the least
significant returned digit of a rounded result is to be calculated.
If fewer digits are returned than the digits needed to represent
the exact numerical result, the discarded digits will be referred
to as the *discarded fraction* regardless the digits'
contribution to the value of the number. In other words,
considered as a numerical value, the discarded fraction could have
an absolute value greater than one.

Each rounding mode description includes a table listing how
different two-digit decimal values would round to a one digit
decimal value under the rounding mode in question. The result
column in the tables could be gotten by creating a
`BigDecimal` number with the specified value, forming a
`https://developer.android.com/reference/java/math/MathContext` object with the proper settings
(`precision` set to `1`, and the
`roundingMode` set to the rounding mode in question), and
calling `https://developer.android.com/reference/java/math/BigDecimal#round(java.math.MathContext)` on this number with the
proper `MathContext`. A summary table showing the results
of these rounding operations for all rounding modes appears below.

| Input Number | Result of rounding input to one digit with the given rounding mode ||||||||
| Input Number | `UP` | `DOWN` | `CEILING` | `FLOOR` | `HALF_UP` | `HALF_DOWN` | `HALF_EVEN` | `UNNECESSARY` |
| 5.5 | 6 | 5 | 6 | 5 | 6 | 5 | 6 | throw `ArithmeticException` |
| 2.5 | 3 | 2 | 3 | 2 | 3 | 2 | 2 | throw `ArithmeticException` |
| 1.6 | 2 | 1 | 2 | 1 | 2 | 2 | 2 | throw `ArithmeticException` |
| 1.1 | 2 | 1 | 2 | 1 | 1 | 1 | 1 | throw `ArithmeticException` |
| 1.0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| -1.0 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
| -1.1 | -2 | -1 | -1 | -2 | -1 | -1 | -1 | throw `ArithmeticException` |
| -1.6 | -2 | -1 | -1 | -2 | -2 | -2 | -2 | throw `ArithmeticException` |
| -2.5 | -3 | -2 | -2 | -3 | -3 | -2 | -2 | throw `ArithmeticException` |
| -5.5 | -6 | -5 | -5 | -6 | -6 | -5 | -6 | throw `ArithmeticException` |
|---|---|---|---|---|---|---|---|---|
[**Summary of Rounding Operations Under Different Rounding Modes**]

This `enum` is intended to replace the integer-based
enumeration of rounding mode constants in `https://developer.android.com/reference/java/math/BigDecimal`
(`https://developer.android.com/reference/java/math/BigDecimal#ROUND_UP`, `https://developer.android.com/reference/java/math/BigDecimal#ROUND_DOWN`,
etc. ).
**See also:**

- `https://developer.android.com/reference/java/math/BigDecimal`
- `https://developer.android.com/reference/java/math/MathContext`

## Summary

| ### Enum values ||
|---|---|
| `https://developer.android.com/reference/java/math/RoundingMode` | `CEILING` Rounding mode to round towards positive infinity. |
| `https://developer.android.com/reference/java/math/RoundingMode` | `DOWN` Rounding mode to round towards zero. |
| `https://developer.android.com/reference/java/math/RoundingMode` | `FLOOR` Rounding mode to round towards negative infinity. |
| `https://developer.android.com/reference/java/math/RoundingMode` | `HALF_DOWN` Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. |
| `https://developer.android.com/reference/java/math/RoundingMode` | `HALF_EVEN` Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. |
| `https://developer.android.com/reference/java/math/RoundingMode` | `HALF_UP` Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. |
| `https://developer.android.com/reference/java/math/RoundingMode` | `UNNECESSARY` Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary. |
| `https://developer.android.com/reference/java/math/RoundingMode` | `UP` Rounding mode to round away from zero. |

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/java/math/RoundingMode` | ` https://developer.android.com/reference/java/math/RoundingMode#valueOf(java.lang.String)(https://developer.android.com/reference/java/lang/String name) ` |
| ` static https://developer.android.com/reference/java/math/RoundingMode` | ` https://developer.android.com/reference/java/math/RoundingMode#valueOf(int)(int rm) ` Returns the `RoundingMode` object corresponding to a legacy integer rounding mode constant in `https://developer.android.com/reference/java/math/BigDecimal`. |
| ` static final https://developer.android.com/reference/java/math/RoundingMode` | ` https://developer.android.com/reference/java/math/RoundingMode#values()() ` |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Enum

` `


final

https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Enum#clone()()
`

Throws CloneNotSupportedException.


`


final

int` `
https://developer.android.com/reference/java/lang/Enum#compareTo(E)(https://developer.android.com/reference/java/math/RoundingMode o)
`

Compares this enum with the specified object for order.


`


final

boolean` `
https://developer.android.com/reference/java/lang/Enum#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object other)
`

Returns true if the specified object is equal to this
enum constant.


`


final

void` `
https://developer.android.com/reference/java/lang/Enum#finalize()()
`

enum classes cannot have finalize methods.


`


final

https://developer.android.com/reference/java/lang/Class<https://developer.android.com/reference/java/math/RoundingMode>` `
https://developer.android.com/reference/java/lang/Enum#getDeclaringClass()()
`

Returns the Class object corresponding to this enum constant's
enum type.


`


final

int` `
https://developer.android.com/reference/java/lang/Enum#hashCode()()
`

Returns a hash code for this enum constant.


`


final

https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Enum#name()()
`

Returns the name of this enum constant, exactly as declared in its
enum declaration.


`


final

int` `
https://developer.android.com/reference/java/lang/Enum#ordinal()()
`

Returns the ordinal of this enumeration constant (its position
in its enum declaration, where the initial constant is assigned
an ordinal of zero).


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Enum#toString()()
`

Returns the name of this enum constant, as contained in the
declaration.


`


static

<T extends https://developer.android.com/reference/java/lang/Enum<T>>
T` `
https://developer.android.com/reference/java/lang/Enum#valueOf(java.lang.Class<T>,%20java.lang.String)(https://developer.android.com/reference/java/lang/Class<T> enumClass, https://developer.android.com/reference/java/lang/String name)
`

Returns the enum constant of the specified enum class with the
specified name.


From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


From interface `

https://developer.android.com/reference/java/lang/Comparable

` `
abstract


int` `
https://developer.android.com/reference/java/lang/Comparable#compareTo(T)(https://developer.android.com/reference/java/math/RoundingMode o)
`

Compares this object with the specified object for order.


## Enum values

### CEILING

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final RoundingMode CEILING
```

Rounding mode to round towards positive infinity. If the
result is positive, behaves as for `RoundingMode.UP`;
if negative, behaves as for `RoundingMode.DOWN`. Note
that this rounding mode never decreases the calculated value.
This mode corresponds to the IEEE 754-2019 rounding-direction
attribute roundTowardPositive.

Example:

| Input Number | Input rounded to one digit with `CEILING` rounding |
| 5.5 | 6 |
| 2.5 | 3 |
| 1.6 | 2 |
| 1.1 | 2 |
| 1.0 | 1 |
| -1.0 | -1 |
| -1.1 | -1 |
| -1.6 | -1 |
| -2.5 | -2 |
| -5.5 | -5 |
|---|---|
[Rounding mode CEILING Examples]

<br />

<br />

### DOWN

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final RoundingMode DOWN
```

Rounding mode to round towards zero. Never increments the digit
prior to a discarded fraction (i.e., truncates). Note that this
rounding mode never increases the magnitude of the calculated value.
This mode corresponds to the IEEE 754-2019 rounding-direction
attribute roundTowardZero.

Example:

| Input Number | Input rounded to one digit with `DOWN` rounding |
| 5.5 | 5 |
| 2.5 | 2 |
| 1.6 | 1 |
| 1.1 | 1 |
| 1.0 | 1 |
| -1.0 | -1 |
| -1.1 | -1 |
| -1.6 | -1 |
| -2.5 | -2 |
| -5.5 | -5 |
|---|---|
[Rounding mode DOWN Examples]

<br />

<br />

### FLOOR

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final RoundingMode FLOOR
```

Rounding mode to round towards negative infinity. If the
result is positive, behave as for `RoundingMode.DOWN`;
if negative, behave as for `RoundingMode.UP`. Note that
this rounding mode never increases the calculated value.
This mode corresponds to the IEEE 754-2019 rounding-direction
attribute roundTowardNegative.

Example:

| Input Number | Input rounded to one digit with `FLOOR` rounding |
| 5.5 | 5 |
| 2.5 | 2 |
| 1.6 | 1 |
| 1.1 | 1 |
| 1.0 | 1 |
| -1.0 | -1 |
| -1.1 | -2 |
| -1.6 | -2 |
| -2.5 | -3 |
| -5.5 | -6 |
|---|---|
[Rounding mode FLOOR Examples]

<br />

<br />

### HALF_DOWN

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final RoundingMode HALF_DOWN
```

Rounding mode to round towards "nearest neighbor"
unless both neighbors are equidistant, in which case round
down. Behaves as for `RoundingMode.UP` if the discarded
fraction is \> 0.5; otherwise, behaves as for
`RoundingMode.DOWN`.

Example:

| Input Number | Input rounded to one digit with `HALF_DOWN` rounding |
| 5.5 | 5 |
| 2.5 | 2 |
| 1.6 | 2 |
| 1.1 | 1 |
| 1.0 | 1 |
| -1.0 | -1 |
| -1.1 | -1 |
| -1.6 | -2 |
| -2.5 | -2 |
| -5.5 | -5 |
|---|---|
[Rounding mode HALF_DOWN Examples]

<br />

<br />

### HALF_EVEN

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final RoundingMode HALF_EVEN
```

Rounding mode to round towards the "nearest neighbor"
unless both neighbors are equidistant, in which case, round
towards the even neighbor. Behaves as for
`RoundingMode.HALF_UP` if the digit to the left of the
discarded fraction is odd; behaves as for
`RoundingMode.HALF_DOWN` if it's even. Note that this
is the rounding mode that statistically minimizes cumulative
error when applied repeatedly over a sequence of calculations.
It is sometimes known as "Banker's rounding," and is
chiefly used in the USA. This rounding mode is analogous to
the rounding policy used for `float` and `double`
arithmetic in Java.
This mode corresponds to the IEEE 754-2019 rounding-direction
attribute roundTiesToEven.

Example:

| Input Number | Input rounded to one digit with `HALF_EVEN` rounding |
| 5.5 | 6 |
| 2.5 | 2 |
| 1.6 | 2 |
| 1.1 | 1 |
| 1.0 | 1 |
| -1.0 | -1 |
| -1.1 | -1 |
| -1.6 | -2 |
| -2.5 | -2 |
| -5.5 | -6 |
|---|---|
[Rounding mode HALF_EVEN Examples]

<br />

<br />

### HALF_UP

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final RoundingMode HALF_UP
```

Rounding mode to round towards "nearest neighbor"
unless both neighbors are equidistant, in which case round up.
Behaves as for `RoundingMode.UP` if the discarded
fraction is ≥ 0.5; otherwise, behaves as for
`RoundingMode.DOWN`. Note that this is the rounding
mode commonly taught at school.
This mode corresponds to the IEEE 754-2019 rounding-direction
attribute roundTiesToAway.

Example:

| Input Number | Input rounded to one digit with `HALF_UP` rounding |
| 5.5 | 6 |
| 2.5 | 3 |
| 1.6 | 2 |
| 1.1 | 1 |
| 1.0 | 1 |
| -1.0 | -1 |
| -1.1 | -1 |
| -1.6 | -2 |
| -2.5 | -3 |
| -5.5 | -6 |
|---|---|
[Rounding mode HALF_UP Examples]

<br />

<br />

### UNNECESSARY

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final RoundingMode UNNECESSARY
```

Rounding mode to assert that the requested operation has an exact
result, hence no rounding is necessary. If this rounding mode is
specified on an operation that yields an inexact result, an
`ArithmeticException` is thrown.

Example:

| Input Number | Input rounded to one digit with `UNNECESSARY` rounding |
| 5.5 | throw `ArithmeticException` |
| 2.5 | throw `ArithmeticException` |
| 1.6 | throw `ArithmeticException` |
| 1.1 | throw `ArithmeticException` |
| 1.0 | 1 |
| -1.0 | -1 |
| -1.1 | throw `ArithmeticException` |
| -1.6 | throw `ArithmeticException` |
| -2.5 | throw `ArithmeticException` |
| -5.5 | throw `ArithmeticException` |
|---|---|
[Rounding mode UNNECESSARY Examples]

<br />

<br />

### UP

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final RoundingMode UP
```

Rounding mode to round away from zero. Always increments the
digit prior to a non-zero discarded fraction. Note that this
rounding mode never decreases the magnitude of the calculated
value.

Example:

| Input Number | Input rounded to one digit with `UP` rounding |
| 5.5 | 6 |
| 2.5 | 3 |
| 1.6 | 2 |
| 1.1 | 2 |
| 1.0 | 1 |
| -1.0 | -1 |
| -1.1 | -2 |
| -1.6 | -2 |
| -2.5 | -3 |
| -5.5 | -6 |
|---|---|
[Rounding mode UP Examples]

<br />

<br />

## Public methods

### valueOf

```
public static RoundingMode valueOf (String name)
```

<br />

<br />

| Parameters ||
|---|---|
| `name` | `String` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/RoundingMode` | <br /> |

### valueOf

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static RoundingMode valueOf (int rm)
```

Returns the `RoundingMode` object corresponding to a
legacy integer rounding mode constant in `https://developer.android.com/reference/java/math/BigDecimal`.

<br />

| Parameters ||
|---|---|
| `rm` | `int`: legacy integer rounding mode to convert <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/RoundingMode` | `RoundingMode` corresponding to the given integer. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | integer is out of range |

### values

```
public static final RoundingMode[] values ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/RoundingMode` | <br /> |