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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Benefitz Posted May 29, 2011 Author Share Posted May 29, 2011 Silly me, lol. Thanks man. Quote Link to comment Share on other sites More sharing options...
silkfire Posted June 12, 2011 Share Posted June 12, 2011 Very simple: echo round(2/3 * 100) . '%'; Quote Link to comment 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.