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 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 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? 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() 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 ! Link to comment https://forums.phpfreaks.com/topic/34900-keeping-0s/#findComment-164559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.