how to implement calculation of percents:
$x=3;
$y = 100\$x; // 3.333..
$x*$y - and here I need to get 100 without Observational error
Any ideas?
how to implement calculation of percents:
$x=3;
$y = 100\$x; // 3.333..
$x*$y - and here I need to get 100 without Observational error
Any ideas?
Your backslash (\
) is not the division symbol. You must use division /
symbol.
Here's an example using number_format()
which will round to two decimal places (the hundredths position).
$x = 3;
$y = 15;
$percent = $x/$y;
$percent_friendly = number_format( $percent * 100, 2 ) . '%'; // change 2 to # of decimals