relativeChange

Creates a Percentage which represents the relative change of this number to another number. Calculations using it won't be rounded. Example:

1.changeOf(5) // 400%

Or using the infix notation:

1 changeOf 5

When this number is zero, an IllegalArgumentException exception is thrown as the relative change for this case is not defined.

When both numbers are zero, a Percentage(0) is returned meaning no change happened instead of returning a Percentage(NaN) (which would happen as a result o dividing 0 by 0, both computationally and mathematically).

Receiver

Number

Return

A Percentage that represents the percentage change of this number and the other number.

Parameters

other

The other number.

Throws

When this number is zero.


fun Number.relativeChange(other: Number, precision: Int): Percentage(source)

Creates a Percentage which represents the relative change of this number to another number. Calculations using it will be rounded. Example:

1.changeOf(5, 2) // 400%

When this number is zero, an IllegalArgumentException exception is thrown as the relative change for this case is not defined.

When both numbers are zero, a Percentage(0) is returned meaning no change happened instead of returning a Percentage(NaN) (which would happen as a result o dividing 0 by 0, both computationally and mathematically).

Receiver

Number

Return

A Percentage that represents the percentage change of this number and the other number.

Parameters

other

The other number.

precision

The precision scale to round percentage calculations. The rounding is done using the PreciseRounding policy (i.e. rounds using RoundingMode.HALF_EVEN mode).

Throws

When this number is zero.


Creates a Percentage which represents the relative change of this number to another number. Calculations using it will be rounded. Example:

1.changeOf(5, Rounding.to(2, RoundingMode.HALF_DOWN)) // 400%

When this number is zero, an IllegalArgumentException exception is thrown as the relative change for this case is not defined.

When both numbers are zero, a Percentage(0) is returned meaning no change happened instead of returning a Percentage(NaN) (which would happen as a result o dividing 0 by 0, both computationally and mathematically).

Receiver

Number

Return

A Percentage that represents the percentage change of this number and the other number.

Parameters

other

The other number.

rounding

The Rounding strategy to round the percentage calculations.

Throws

When this number is zero.