as Percentage
Calculates what fraction this number is of a given value.
This function is useful for determining the proportion of one number relative to another, often as a preliminary step before formatting as a percentage (e.g., by multiplying by 100). The result is a Float to preserve decimal precision.
Example:
val part = 50
val total = 200
val fraction = part.asPercentage(total) // Result will be 0.25f
val percentage = fraction * 100 // 25.0Content copied to clipboard
Return
The fractional value of this number in relation to ofValue, as a Float.
Parameters
of Value
The total value to calculate the percentage against. This is the denominator.