GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php - why does this happen? (https://gfy.com/showthread.php?t=151798)

cj-design 07-11-2003 11:08 AM

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?

cezam 07-11-2003 11:13 AM

it's 5.00, so print strips the decimal places off.

printf is your friend, check manual.

jovigirl 07-11-2003 11:13 AM

i dont wanna buy zoom glasses

Brujah 07-11-2003 11:13 AM

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

rowan 07-11-2003 11:15 AM

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.

cj-design 07-11-2003 11:22 AM

cheers boys.

Thorin 07-11-2003 11:40 AM

Quote:

Originally posted by cj-design
What happened to the decimal places on the saving?

...

PHP/MySQL Programmer

Wow...

Freestyleman 07-11-2003 11:42 AM

Quote:

Originally posted by Thorin



Wow...


:1orglaugh :1orglaugh :1orglaugh

JamesK 07-11-2003 11:44 AM

Quote:

Originally posted by jovigirl
i dont wanna buy zoom glasses
HAHAHAHAAHAHHA


All times are GMT -7. The time now is 07:31 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123