tommy445 Posted March 9, 2009 Share Posted March 9, 2009 i have placed an echo string in a table however i am unable to format the number with commas and decimals. Java functions don't seem to work and I don't understand how to apply the number format form the manual... please help. Here is the echo string: <? echo $row['client_union_dues'];?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/148537-solved-formatting-echo-strings/ Share on other sites More sharing options...
Maq Posted March 9, 2009 Share Posted March 9, 2009 1) NEVER use short tags always use <?php. 2) Why are you talking about java functions? 3) I fail to see where you even try to format... Quote Link to comment https://forums.phpfreaks.com/topic/148537-solved-formatting-echo-strings/#findComment-780019 Share on other sites More sharing options...
tommy445 Posted March 9, 2009 Author Share Posted March 9, 2009 results from <? echo $row['client_primary_job'];?> returns 1000 results from <? echo $row['client_primary_job']; printf ("%01.2f", $client_primary_job)?> returns 10000.00 The decimal is o.k. but what's up with the extra zero to the number.? Any ideas? thx Quote Link to comment https://forums.phpfreaks.com/topic/148537-solved-formatting-echo-strings/#findComment-780044 Share on other sites More sharing options...
Maq Posted March 9, 2009 Share Posted March 9, 2009 $row['client_primary_job'] AND $client_primary_job are two different variables... Anyway, I don't know what's wrong because this works for me: $client_primary_job = 1000; printf ("%01.2f", $client_primary_job) ?> output 1000.00 Quote Link to comment https://forums.phpfreaks.com/topic/148537-solved-formatting-echo-strings/#findComment-780048 Share on other sites More sharing options...
tommy445 Posted March 9, 2009 Author Share Posted March 9, 2009 O.K. i had to declare variable $client_primary_job = $row['client_primary_job']; from my mysql query. Then i used <?php print ("%01.2f, $client_primary_job) ?> to get my decimals. Two things. Do I now have to do this for all 60+ fields in the table? or is there a global way of doing it. And, how am I to get the comma in that string? thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/148537-solved-formatting-echo-strings/#findComment-780062 Share on other sites More sharing options...
kenrbnsn Posted March 9, 2009 Share Posted March 9, 2009 I would use the number_format function to get both the comma and decimal point: <?php echo number_format($row['client_primary_job'],2); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/148537-solved-formatting-echo-strings/#findComment-780108 Share on other sites More sharing options...
Maq Posted March 9, 2009 Share Posted March 9, 2009 O.K. i had to declare variable $client_primary_job = $row['client_primary_job']; from my mysql query. Then i used <?php print ("%01.2f, $client_primary_job) ?> to get my decimals. Two things. Do I now have to do this for all 60+ fields in the table? or is there a global way of doing it. And, how am I to get the comma in that string? thanks again. ken's answer works, I also answered in your other thread with the same solution... Quote Link to comment https://forums.phpfreaks.com/topic/148537-solved-formatting-echo-strings/#findComment-780321 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.