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 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); 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 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 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 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 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 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 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 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 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, ".", ""); ?> Link to comment https://forums.phpfreaks.com/topic/113227-display-as-double/#findComment-581755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.