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
Old 03-13-2005, 02:12 PM rounding?
Extreme Talker

Posts: 219
Location: UK, East Anglia
Trades: 0
I'm not sure how to explain this,
I need $num to look like a currency, so if it was '1' then it would be changed to '1.00', if it was '1.5 it' would be 1.50 and if it was '1.789' it would be 1.79, i thought that maybe i could use round() but i'm not sure how.
timsquash5 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-13-2005, 02:18 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
round() can take two parameters, one is the number itself and the other is the number of digits after the decimal. So if you supply '2' as the second paramter, then it should do what you want.

PHP Code:
$cost round(1023.96872);
echo 
'$' $cost// $1023.97 
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 03-13-2005, 02:22 PM
Extreme Talker

Posts: 219
Location: UK, East Anglia
Trades: 0
i have already tried that, but it just leaves 1 as 1 it doesn't add .00.
timsquash5 is offline
Reply With Quote
View Public Profile
 
Old 03-13-2005, 02:32 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
If there isn't already a decimal, then you can just use number_format() combined with round to do the job.

PHP Code:
$cost 1;

$cost number_format(round($cost2), 2);

echo 
$cost// 1.00 
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 03-13-2005, 02:32 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Use number_format($number, 2);That'll get you two decimal places, and add zeroes if necessary.

EDIT: D'oh! Just too late!!
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-13-2005, 02:43 PM
Extreme Talker

Posts: 219
Location: UK, East Anglia
Trades: 0
thank you, both
timsquash5 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to rounding?
 

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.17008 seconds with 12 queries