View Full Version : decimal point
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???
01-04-2008, 08:33 PM
it didint solve my problem
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.
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
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.
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 .
01-05-2008, 04:42 AM
$number1 = 5;
$number2 = 3;
$result = round($number1/$number2,1);
Is that what you're looking for?
Yes , thats exactly what I want.
01-05-2008, 06:30 PM
For future reference that was the round() function it can be used:
$string = "7.938";
$string = round($string, '2');
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.