another 3 questions about PHP

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
User avatar
rax369
Forum Commoner
Posts: 56
Joined: Sun Oct 06, 2002 8:50 pm

another 3 questions about PHP

Post 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
daynah
Forum Newbie
Posts: 6
Joined: Fri Oct 25, 2002 12:48 pm
Location: USA

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

Post by volka »

2) mayor number?
could be MAX(field), too
User avatar
rax369
Forum Commoner
Posts: 56
Joined: Sun Oct 06, 2002 8:50 pm

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

Post by volka »

User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Try bcmul().
Post Reply