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.

Example:

<table class="striped"> <caption>Rounding mode HALF_EVEN Examples</caption> <thead> <tr style="vertical-align:top"><th scope="col">Input Number</th> <th scope="col">Input rounded to one digit<br></br> with `HALF_EVEN` rounding </th></tr></thead> * <tbody style="text-align:right"> <tr><th scope="row">5.5</th> <td>6</td> </tr> * <tr><th scope="row">2.5</th> <td>2</td> </tr> * <tr><th scope="row">1.6</th> <td>2</td> </tr> * <tr><th scope="row">1.1</th> <td>1</td> </tr> * <tr><th scope="row">1.0</th> <td>1</td> </tr> * <tr><th scope="row">-1.0</th> <td>-1</td> </tr> * <tr><th scope="row">-1.1</th> <td>-1</td> </tr> * <tr><th scope="row">-1.6</th> <td>-2</td> </tr> * <tr><th scope="row">-2.5</th> <td>-2</td> </tr> * <tr><th scope="row">-5.5</th> <td>-6</td> </tr></tbody> * </table> *

Functions

clone
Link copied to clipboard
common
protected fun clone(): Any
compareTo
Link copied to clipboard
common
operator override fun compareTo(other: RoundingMode): Int
equals
Link copied to clipboard
common
operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
override fun hashCode(): Int
toString
Link copied to clipboard
common
open override fun toString(): String

Properties

name
Link copied to clipboard
common
val name: String
oldMode
Link copied to clipboard
common
internal val oldMode: Int
The BigDecimal constant corresponding to this mode
ordinal
Link copied to clipboard
common
val ordinal: Int