![]() |
php - why does this happen?
PHP Code:
RRP: 19.99 Price: 14.99 Saving 5 Added Together 34.98 What happened to the decimal places on the saving? |
it's 5.00, so print strips the decimal places off.
printf is your friend, check manual. |
i dont wanna buy zoom glasses
|
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 |
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.
|
cheers boys.
|
Quote:
Wow... |
Quote:
:1orglaugh :1orglaugh :1orglaugh |
Quote:
|
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