Page 1 of 1

another 3 questions about PHP

Posted: Fri Oct 25, 2002 12:09 pm
by rax369
... well people, this time is about PHP functions:

1) What function use to format the output of a calculation:

i.e. 35.26 x 142.99 = 5041.8274

but I'd like to show this quantity like this: 5041.83 :wink: (only 2 decimal, and the 2nd decimal must be approximate to the next number if the 3rd. one is >= 5)

2) is there some function on PHP to get the mayor number stored in a colum table of any MySQL Database :?:

3) if a value in a table is null, and I increment in one, this value would be a problem ? (I'm incrementing in one the value 'cause suppostly there is a number stored there, so I dont know if would be a problem incrementing in one a null value)

thx for ur valuable help guys! :D

Posted: Fri Oct 25, 2002 12:48 pm
by daynah
1) use the sprintf statement printing 2 decimal places of a floating point variable.

Code: Select all

<?php
$a = 35.26; 
$b = 142.99;
$total = $a * $b;
$total = sprintf("%.2f",  $total);
?>
2) mayor number? I'm not sure what you mean, but you can use the MYSQL function COUNT(*). Just be sure to give it a variable in the query and you'll be able to output it.

3) I think null be read as 0 if the field is an 'int'. However, I'm not really certain.

Posted: Fri Oct 25, 2002 12:59 pm
by volka
2) mayor number?
could be MAX(field), too

Posted: Fri Oct 25, 2002 2:36 pm
by rax369
yea, the mayor number stored in a colum from some table.

i.e: pretent that this colum exist in some table

|id_prod|
------------
| 4 |
| 7 |
| 9 |
| 2 |
| 3 |

Here the mayor or the maximun number would be 9, got it ? (sorry maybe I wasnt clear 'cause my english :oops: )

But yes, I need a function that returns the maximum number, I guess is that one u mentioned volka :arrow: 'MAX()'

Posted: Sat Oct 26, 2002 3:09 am
by volka

Posted: Sat Oct 26, 2002 12:29 pm
by hob_goblin
http://www.php.net/round
http://www.php.net/ceil
http://www.php.net/floor

for the first one.. i find them easier than sprintf

Posted: Sat Oct 26, 2002 2:53 pm
by Takuma
Try bcmul().