ratioOf

infix fun Number.ratioOf(other: Number): Percentage(source)

Creates a Percentage based on the ratio of this number and other number. Calculations using it won't be rounded. Example:

1.ratioOf(5) // 20%

Or using the infix notation:

1 ratioOf 5

Receiver

Number

Return

A Percentage that represents the ratio of this number and the other number.

Parameters

other

The other number.

See also

Throws


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

Creates a Percentage based on the ratio of this number and other number. Calculations using it will be rounded. Example:

1.ratioOf(5, 2) // 20%

Receiver

Number

Return

A Percentage that represents the ratio 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).

See also

Throws


fun Number.ratioOf(other: Number, rounding: Rounding): Percentage(source)

Creates a Percentage based on the ratio of this number and other number. Calculations using it will be rounded. Example:

1.ratioOf(5, Rounding.to(2, RoundingMode.HALF_DOWN)) // 20%

Receiver

Number

Return

A Percentage that represents the ratio of this number and the other number.

Parameters

other

The other number.

rounding

The Rounding strategy to round the percentage calculations.

See also

Throws