glenelkins Posted July 4, 2008 Share Posted July 4, 2008 Hi Quick question I want to output the a number as a double. Say the input was "5" i want it to display like "5.00" How can this be done? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/ Share on other sites More sharing options...
interpim Posted July 4, 2008 Share Posted July 4, 2008 sprintf("%10,2", $variable); Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581689 Share on other sites More sharing options...
glenelkins Posted July 4, 2008 Author Share Posted July 4, 2008 thanks Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581693 Share on other sites More sharing options...
glenelkins Posted July 4, 2008 Author Share Posted July 4, 2008 doesnt display anything when i use that code Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581694 Share on other sites More sharing options...
interpim Posted July 4, 2008 Share Posted July 4, 2008 sorry.... i miss typed earlier sprintf("%10,2f", $variable); I left out the f Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581695 Share on other sites More sharing options...
glenelkins Posted July 4, 2008 Author Share Posted July 4, 2008 still doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581716 Share on other sites More sharing options...
teynon Posted July 4, 2008 Share Posted July 4, 2008 Did you output the variable? Heh Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581718 Share on other sites More sharing options...
interpim Posted July 4, 2008 Share Posted July 4, 2008 try this on a test page to begin with <?php $variable = 5; sprintf("%10,2f", $variable); ?> it should spit out 5.00 on the page Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581737 Share on other sites More sharing options...
kenrbnsn Posted July 4, 2008 Share Posted July 4, 2008 That code will not print anything, since the sprintf() function returns a string. If you want to output it do either <?php $variable = 5; echo sprintf("%10,2f", $variable); ?> or <?php $variable = 5; printf("%10,2f", $variable); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581748 Share on other sites More sharing options...
interpim Posted July 4, 2008 Share Posted July 4, 2008 lol doh Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581750 Share on other sites More sharing options...
br0ken Posted July 4, 2008 Share Posted July 4, 2008 <?php $var = 5; echo number_format($var, 2, ".", ""); ?> Quote Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581755 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.