Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 07-11-2003, 11:08 AM   #1
cj-design
Confirmed User
 
Join Date: Apr 2003
Location: England
Posts: 378
php - why does this happen?

PHP Code:
$rrp "19.99";
$price "14.99";
$saving $rrp $price;
$adding $rrp $price;

print 
"RRP: $rrp";
print 
"<p>";
print 
"Price: $price";
print 
"<P>";
print 
"Saving $saving";
print 
"<P>";
print 
"Added Together $adding"
Output:

RRP: 19.99
Price: 14.99

Saving 5

Added Together 34.98


What happened to the decimal places on the saving?
cj-design is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-11-2003, 11:13 AM   #2
cezam
Confirmed User
 
Join Date: Jun 2003
Location: CZ, EU
Posts: 1,363
it's 5.00, so print strips the decimal places off.

printf is your friend, check manual.
__________________
cezam is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-11-2003, 11:13 AM   #3
jovigirl
Confirmed User
 
jovigirl's Avatar
 
Join Date: Apr 2003
Location: On the edge
Posts: 1,796
i dont wanna buy zoom glasses
__________________
ICQ :333-548-380
jovigirl is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-11-2003, 11:13 AM   #4
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
it doesn't keep the format, you can use sprintf to do it.. instead of print.

$saving = sprintf( "%01.2f", $rrp - $price );

http://www.php.net/sprintf
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-11-2003, 11:15 AM   #5
rowan
Too lazy to set a custom title
 
Join Date: Mar 2002
Location: Australia
Posts: 17,393
Be careful using decimal places for pricing, you can get some strange effects with floats... probably better to calculate everything in cents internally (as a whole number), and then divide it by 100 to display it.
rowan is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-11-2003, 11:22 AM   #6
cj-design
Confirmed User
 
Join Date: Apr 2003
Location: England
Posts: 378
cheers boys.
cj-design is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-11-2003, 11:40 AM   #7
Thorin
Registered User
 
Join Date: May 2002
Location: Porn Ghetto
Posts: 44
Quote:
Originally posted by cj-design
What happened to the decimal places on the saving?

...

PHP/MySQL Programmer

Wow...
Thorin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-11-2003, 11:42 AM   #8
Freestyleman
Confirmed User
 
Join Date: Sep 2002
Posts: 283
Quote:
Originally posted by Thorin



Wow...

Freestyleman is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-11-2003, 11:44 AM   #9
JamesK
hi
 
Industry Role:
Join Date: Jun 2002
Posts: 16,731
Quote:
Originally posted by jovigirl
i dont wanna buy zoom glasses
HAHAHAHAAHAHHA
__________________
M3Server - NATS Hosting
JamesK is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.