Adam Posted January 19, 2007 Share Posted January 19, 2007 I have created a shopping cart script and all works perfect, apart from the totals! They are returning as £20.5, £19.8, etc, when the last number is a 0. How do i stop PHP from removing the 0's ?-Thanks Quote Link to comment https://forums.phpfreaks.com/topic/34900-keeping-0s/ Share on other sites More sharing options...
kenrbnsn Posted January 19, 2007 Share Posted January 19, 2007 Look at the [url=http://www.php.net/number_format]number_format()[/url] function.Ken Quote Link to comment https://forums.phpfreaks.com/topic/34900-keeping-0s/#findComment-164552 Share on other sites More sharing options...
simcoweb Posted January 19, 2007 Share Posted January 19, 2007 Could you use the printf function for this as well? Quote Link to comment https://forums.phpfreaks.com/topic/34900-keeping-0s/#findComment-164554 Share on other sites More sharing options...
SharkBait Posted January 19, 2007 Share Posted January 19, 2007 I'd use the [code=php:0]number_format($price, 2);[/code] instead of printf() Quote Link to comment https://forums.phpfreaks.com/topic/34900-keeping-0s/#findComment-164555 Share on other sites More sharing options...
Adam Posted January 19, 2007 Author Share Posted January 19, 2007 number_format($price, 2); - has worked great thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/34900-keeping-0s/#findComment-164559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.