Grandioso Posted November 4, 2010 Share Posted November 4, 2010 Sorry for posting here but this isn't worth creating a new thread. How do I make php to convert float to string with a 2 digit precision ? From 9.50 I get 9.5, but I want 9.50. Quote Link to comment https://forums.phpfreaks.com/topic/217772-re-help-with-float-numbers-in-php/ Share on other sites More sharing options...
Grandioso Posted November 5, 2010 Author Share Posted November 5, 2010 I'm pretty sure I posted this in the "help with float numbers in php" thread. Whatever. Can anyone help me with this ? Quote Link to comment https://forums.phpfreaks.com/topic/217772-re-help-with-float-numbers-in-php/#findComment-1130668 Share on other sites More sharing options...
Pikachu2000 Posted November 5, 2010 Share Posted November 5, 2010 If you posted the question on the tail of another thread, it was probably split off by one of the other mods, or an admin. It'll get more visibility this way anyhow. To answer your question, you can use number_format(). $float = 9646.15659; echo number_format( $float, 2, '.', ',' ); //returns 9,646.16 Quote Link to comment https://forums.phpfreaks.com/topic/217772-re-help-with-float-numbers-in-php/#findComment-1130758 Share on other sites More sharing options...
Grandioso Posted November 6, 2010 Author Share Posted November 6, 2010 works like a charm. thanks Quote Link to comment https://forums.phpfreaks.com/topic/217772-re-help-with-float-numbers-in-php/#findComment-1131140 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.