format() that display a number always! with two trailing digits?Examples:
Code: Select all
510 => 510.00
510.5 => 510.50
510.70 => 510.70
510.428 => 510.42 (no rounding wanted)
15386 => 15386.00
format() that display a number always! with two trailing digits?Code: Select all
510 => 510.00
510.5 => 510.50
510.70 => 510.70
510.428 => 510.42 (no rounding wanted)
15386 => 15386.00
Code: Select all
$n = 510.428; echo format(floor($n * 100) / 100, "0.00");Code: Select all
function getDecimal($num, $cntDigits=2) {
$factor = 10 ^ $cntDigits;
return format(floor($num * $factor) / $factor, "0." . strrepeat("0", $cntDigits));
}
100 it should be 10 ^ $cntDigits.