Oihana PHP

percentage.php

Table of Contents

Functions

percentage()  : float
Computes which percentage a part represents of a total.

Functions

percentage()

Computes which percentage a part represents of a total.

percentage(int|float $part, int|float $total) : float

Returns ( $part / $total ) * 100. As a guard against division by zero, a $total of 0 yields 0.0 rather than raising an error.

Parameters
$part : int|float

The partial amount.

$total : int|float

The total amount.

Tags
example
use function oihana\core\numbers\percentage;

percentage( 25 , 200 ) ; // 12.5
percentage( 1 , 3 )    ; // 33.333333333333
percentage( 5 , 0 )    ; // 0.0 (division-by-zero guard)
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
float

The percentage in the [0, 100] range for in-bounds inputs, 0.0 when $total is 0.

On this page

Search results