Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Add code for decimal places
Old 11-21-2010, 08:33 PM Add code for decimal places
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Good day!
I want to know where I can put this code :
PHP Code:
 number_format($num), 2
I have this code:
PHP Code:
echo mysql_result ($result,$ctr,"inputqty"); 
I want the output if this code is in 2 decimal places for example the output in this code is: 1.9856211 I want to become is like this 1.99
I hope somebody can help me...thank you..
newphpcoder is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-21-2010, 10:24 PM Re: Add code for decimal places
Mime's Avatar
Extreme Talker

Posts: 164
Name: Seb
Trades: 0
Now, I don't really no much (if anything at all!) about PHP but as nobody has replied yet I'll chip in here.

number_format() is a PHP function (I'm just writing my observations down here, I know you know that it's a function) but you appear to be asking it to write your number up to two decimal places but number_format with a parameter of 2 actually gives you a decimal and a comma between every group of thousands. Not what you want by the sounds of it.

However, round() will achieve what you require.

The actual use of this I'm not sure. Perhaps it will be something like this:

PHP Code:
echo mysql_result ($result,$ctr,round("inputqty".2)); 
But a better method would be to round() the number before putting it in the MySQL database, maybe. Unless you require the full number elsewhere.

As I say, I don't know PHP, and if I haven't confused you further, I hope I've helped somewhat.
Mime is offline
Reply With Quote
View Public Profile
 
Old 11-21-2010, 10:31 PM Re: Add code for decimal places
Average Talker

Posts: 25
Name: Stephen
Location: Arizona
Trades: 0
PHP Code:
echo number_format(round(mysql_result($result,$ctr,"inputqty"),2),2); 
__________________

Please login or register to view this content. Registration is FREE
and
Please login or register to view this content. Registration is FREE
GetGamesHere is offline
Reply With Quote
View Public Profile Visit GetGamesHere's homepage!
 
Old 11-21-2010, 10:46 PM Re: Add code for decimal places
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Quote:
Originally Posted by GetGamesHere View Post
PHP Code:
echo number_format(round(mysql_result($result,$ctr,"inputqty"),2),2); 

Thank you
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 11-21-2010, 10:55 PM Re: Add code for decimal places
Mime's Avatar
Extreme Talker

Posts: 164
Name: Seb
Trades: 0
Good job GetGamesHere.

At least I tried
It's about time I learnt some PHP anyway
Mime is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Add code for decimal places
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39302 seconds with 12 queries