PHP DIVISION OPERATOR

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sj1469
Forum Newbie
Posts: 1
Joined: Mon Sep 22, 2003 3:19 pm

PHP DIVISION OPERATOR

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Post Reply