...

View Full Version : decimal point



skmd
01-04-2008, 08:19 PM
Hi everybody
my script calculate some values from the database and its work fine but i just need to define how many number to show after the decimal point , how can i do it???

PappaJohn
01-04-2008, 08:33 PM
number_format() (http://us3.php.net/manual/en/function.number-format.php)

skmd
01-05-2008, 12:14 AM
it didint solve my problem

PappaJohn
01-05-2008, 12:50 AM
Then you're going to need to show your code. The function I linked to, if used properly, will format the number for display how you want it.

skmd
01-05-2008, 02:18 AM
ok maybe there is a way but I didn't pay attention. anyway
My code result is like this


//suppose $number1=5 and $number2=3
$result = $number1/ $number2;
echo $result; //will print 1.666666666 but i want it to print just 1 number after the decimal point

PappaJohn
01-05-2008, 02:23 AM
Well, no advise is going to solve your problem if you don't "pay attention", or as your code above show, didn't try it.

skmd
01-05-2008, 02:31 AM
I didnt find anything that suit my case, the number_format() as i can see its just count from right to left
Excuse me, im a new coder .

bcarl314
01-05-2008, 04:42 AM
$number1 = 5;
$number2 = 3;
$result = round($number1/$number2,1);
print $result;


Is that what you're looking for?

skmd
01-05-2008, 11:47 AM
Yes , thats exactly what I want.
Thank you

the-dream
01-05-2008, 06:30 PM
For future reference that was the round() function it can be used:


<?php
round($string, 'decimal_places');
?>

Example:


<?php

$string = "7.938";
$string = round($string, '2');

?>

Output: 7.94



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum