otuatail Posted July 14, 2007 Share Posted July 14, 2007 Can anyone tell me whats wrong here. I am trying to format 2 numbers 182.75 * 2 using printf("%09.2f" , ($rs['Cost'] * $rs['Q']) ) instead of getting 000365.50 I get 000365.509 the last digit is the number of zeros on the end. This is a shopping basket totals Desmond. Link to comment https://forums.phpfreaks.com/topic/59978-solved-printf-formatting/ Share on other sites More sharing options...
Guardian-Mage Posted July 14, 2007 Share Posted July 14, 2007 Really, why are you using printf for that type of work? Honestly now, use echo or print. If you need help with those post again, and I will try to help Link to comment https://forums.phpfreaks.com/topic/59978-solved-printf-formatting/#findComment-298300 Share on other sites More sharing options...
otuatail Posted July 14, 2007 Author Share Posted July 14, 2007 Ok i have managed to override all the security on the site. This is the link with the anoying extra "9" http://www.des-otoole.co.uk/shop/AddToBasket.php Link to comment https://forums.phpfreaks.com/topic/59978-solved-printf-formatting/#findComment-298313 Share on other sites More sharing options...
Barand Posted July 14, 2007 Share Posted July 14, 2007 <?php printf("%09.2f" , 182.75 * 2 ); // --> 000365.50 ?> If you don't want leading spaces or zeros, just use "%0.2f". Alternatively echo number_format( 182.75 * 2, 2); // --> 365.50 Link to comment https://forums.phpfreaks.com/topic/59978-solved-printf-formatting/#findComment-298321 Share on other sites More sharing options...
otuatail Posted July 14, 2007 Author Share Posted July 14, 2007 It's not the leading spaces It's that damed 9 on the end that is part of the formatting instruction as in "%09.2f" change that to an 8 and i get less zero's and an 8 on the end. Link to comment https://forums.phpfreaks.com/topic/59978-solved-printf-formatting/#findComment-298324 Share on other sites More sharing options...
otuatail Posted July 14, 2007 Author Share Posted July 14, 2007 Thanks for that Number_format. Does this not allow pagenating as in £****345.45 to keep the pound signs in line. Would look smarter Desmond. Link to comment https://forums.phpfreaks.com/topic/59978-solved-printf-formatting/#findComment-298427 Share on other sites More sharing options...
Barand Posted July 14, 2007 Share Posted July 14, 2007 You could use it in conjunction with str_pad <?php echo '£' . str_pad(number_format(355.500, 2), 9, '*', STR_PAD_LEFT); ?> Link to comment https://forums.phpfreaks.com/topic/59978-solved-printf-formatting/#findComment-298437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.