DaveLinger Posted July 22, 2007 Share Posted July 22, 2007 So I have an assortment of numbers coming in, they're all zero point something. I want them to round to zero point number number - like currency... $0.XX. Problem I'm running into is that when I do round($var, 2), it cuts off trailing zeros, so some numbers end up as $0.X, because the next number would have been a zero. How do I keep that on there? Link to comment https://forums.phpfreaks.com/topic/61294-solved-format-a-number-but-include-trailing-0s/ Share on other sites More sharing options...
dbo Posted July 22, 2007 Share Posted July 22, 2007 Look into sprintf... I don't remember the exact syntax. Link to comment https://forums.phpfreaks.com/topic/61294-solved-format-a-number-but-include-trailing-0s/#findComment-304993 Share on other sites More sharing options...
DaveLinger Posted July 22, 2007 Author Share Posted July 22, 2007 got it: sprintf("%01.2f", $var) Link to comment https://forums.phpfreaks.com/topic/61294-solved-format-a-number-but-include-trailing-0s/#findComment-304998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.