Page 1 of 1

PHP DIVISION OPERATOR

Posted: Mon Sep 22, 2003 3:19 pm
by sj1469
I am fairly new to php. I want to know the easiest way of getting a result like 7.9 or 9.5 or 8.3 A whole number with one decimal place using the division operator. Is this hard to code? Please help.

Posted: Mon Sep 22, 2003 5:37 pm
by volka
no, not hard to do

Code: Select all

<?php
$number = 22.0 / 7.0;  // a float-value

echo number_format($number, 1);
// or
printf("%.1f", $number);
?>
see also:
http://php.net/number_format
http://php.net/printf