Benefitz Posted May 29, 2011 Share Posted May 29, 2011 Hey guys, Simple advice on this one. I'd like to convert a float value to percentage... See the example below: printf("%.2f",2/3); So obviously 0.67 is expected, but I'd like to assume without reinventing the wheel, that PHP has a nice function that prints 67% instead. Anyone? Thanks in advance -Fitz. Link to comment https://forums.phpfreaks.com/topic/237742-format-float-value-to-percentage/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 29, 2011 Share Posted May 29, 2011 without reinventing the wheel What's to reinvent? You need to multiply by 100 to get percent. Don't over complicate things just because you are using a computer to do them. Link to comment https://forums.phpfreaks.com/topic/237742-format-float-value-to-percentage/#findComment-1221748 Share on other sites More sharing options...
Benefitz Posted May 29, 2011 Author Share Posted May 29, 2011 Silly me, lol. Thanks man. Link to comment https://forums.phpfreaks.com/topic/237742-format-float-value-to-percentage/#findComment-1221749 Share on other sites More sharing options...
silkfire Posted June 12, 2011 Share Posted June 12, 2011 Very simple: echo round(2/3 * 100) . '%'; Link to comment https://forums.phpfreaks.com/topic/237742-format-float-value-to-percentage/#findComment-1228792 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.