tommy445 Posted March 8, 2009 Share Posted March 8, 2009 how do i decimal, comma, and $ format numbers called from mysql displayed in table cells using php. This is the call script <? echo $row['table_primary']; ?> and this is the formatting script sample <?php $value = 123456789; echo number_format($value); ?> How do I replace the $value=123... with my call script? Thanks Javascript don't seem to work because the number is being echo'd. Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/ Share on other sites More sharing options...
premiso Posted March 8, 2009 Share Posted March 8, 2009 money_format Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-779776 Share on other sites More sharing options...
tommy445 Posted March 8, 2009 Author Share Posted March 8, 2009 Thanks for responding, however still lost. this is what i've come up with... but it doesn't work <? echo $row['table_primary']; echo money_format(table_primary) ?> ...stop laughing ??? Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-779800 Share on other sites More sharing options...
DjMikeS Posted March 8, 2009 Share Posted March 8, 2009 From the manual: Note: The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows. Are you running this on a Windows host? And what's up with: echo money_format(table_primary); It's not even a variable... And lastly...we can't smell your problem, so please tell us what is going wrong and use the php code tags.... Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-779846 Share on other sites More sharing options...
tommy445 Posted March 8, 2009 Author Share Posted March 8, 2009 OK, I have successfully called data (numbers) from the data base using <? echo $row['table_primary']; ?> My problem is that javascript will not format the numbers unless its in a textbox. How do I format the echo string to show decimals and commas. This must be complex as i see similar questions that went unresolved. Thanks for attempting. Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-779859 Share on other sites More sharing options...
DjMikeS Posted March 8, 2009 Share Posted March 8, 2009 You haven't answered my question. Are you running money_format on a windows host or not? And use the php code tags....that's the second time... Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-779866 Share on other sites More sharing options...
tommy445 Posted March 8, 2009 Author Share Posted March 8, 2009 sorry, running 2.2.11 (Unix) php 4.6??? Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-779870 Share on other sites More sharing options...
DjMikeS Posted March 9, 2009 Share Posted March 9, 2009 Okay, well the piece of code that you gave us is wrong... You might want to check that out before writing of money_format... First,you haven't specified a variable because <? echo money_format(table_primary) ?> table primary is not a variable. Secondly, you haven't specified a conversion character.... <? echo money_format('%i', $row['table_primary']) ?> Read the manual!! http://www.php.net/money_format Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-780127 Share on other sites More sharing options...
tommy445 Posted March 9, 2009 Author Share Posted March 9, 2009 Thanks again for your help, I was able to come up with the following which displays the correct number and 2 decimal points, however I am unable to find the comma solution. <?php printf ("%01.2f", $client_co_union_dues); ?> Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-780372 Share on other sites More sharing options...
DjMikeS Posted March 9, 2009 Share Posted March 9, 2009 Why aren't you using the money_format anymore? Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-780384 Share on other sites More sharing options...
tommy445 Posted March 9, 2009 Author Share Posted March 9, 2009 the money format does work, I just didn't know how to apply it. Got it, thanks Quote Link to comment https://forums.phpfreaks.com/topic/148495-solved-number-formatting/#findComment-780410 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.