twilitegxa Posted August 23, 2009 Share Posted August 23, 2009 Is there a way to code this to where the number line up at the decimals? I was reading about the number_format function, but I can't get it to work right. Can anyone help? Here is the code I wish to use it on: <?php $get_sub_attributes = "select * from scout_sub_attributes where identity = '$identity'"; $get_sub_attributes_res = mysql_query($get_sub_attributes, $conn) or die(mysql_error()); while ($sub_attributes_info = mysql_fetch_array($get_sub_attributes_res)) { $sub_attributes_id = $sub_attributes_info['id']; $sub_attributes_identity = $sub_attributes_info['identity']; $sub_attributes_attribute_id = $sub_attributes_info['sub_attribute_id']; $sub_attributes_level_id = $sub_attributes_info['level_id']; $sub_attributes_notes = $sub_attributes_info['notes']; $get_sub_attribute_names = "select * from sub_attributes where id = '$sub_attributes_attribute_id'"; $get_sub_attribute_names_res = mysql_query($get_sub_attribute_names, $conn) or die(mysql_error()); while ($sub_attribute_names_info = mysql_fetch_array($get_sub_attribute_names_res)) { $sub_attribute_names_id = $sub_attribute_names_info['id']; $sub_attribute_names_attribute = $sub_attribute_names_info['sub_attribute']; $sub_attribute_names_points = $sub_attribute_names_info['points']; $sub_attributes_points = ($sub_attribute_names_points * $sub_attributes_level_id); $display_block .= " <tr> <td class=indent>$sub_attribute_names_attribute</td>"; if ($sub_attributes_level_id == null) { $display_block .= "$sub_attributes_level_id"; } else { $display_block .= " <td class=align_levels>$sub_attributes_level_id</td> <td class=align_levels>$sub_attributes_points</td> </tr>"; } ?> The variables I want decimal aligned are $sub_attributes_level_id and $sub_attributes_points. How can I do this? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 23, 2009 Share Posted August 23, 2009 What's "not right" about echo number_format ($sub_attributes_level_id , 2 , "." , ","); Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 23, 2009 Author Share Posted August 23, 2009 Well, I tried it like this: $sub_attributes_level_id = number_format($sub_attributes_info['level_id']); Is this not how i can do it? Doing this doesn't change the alignment. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 23, 2009 Share Posted August 23, 2009 What do you mean by alignment? what are you trying to do? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 23, 2009 Author Share Posted August 23, 2009 I see what you did, but I can get it to work for this calculation: $sub_attributes_points = ($sub_attribute_names_points * $sub_attributes_level_id); I tried this: $sub_attributes_points = number_format ($sub_attributes_points , 0 , "." , ","); But nothing happened. What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 23, 2009 Author Share Posted August 23, 2009 I am trying to align the numbers that are displayed from the table to the decimal. I also have the column centered. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 23, 2009 Share Posted August 23, 2009 tested here and its doing exactly what it is supposed to do, However I don't know what your expecting it to do! okay for text alignment see CSS/HTML align attribute. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 23, 2009 Author Share Posted August 23, 2009 Well, i already have the text-align set to center on the table cell, so I can't figure out how to do both, so I guess I will close this topic as solved and give up on doing it. What I wanted to do was have the cell centered as well as have the numbers being displayed in it aligned to the decimal: So instead of this - 4 5 10 I'd have: 4 5 10 It is sort of hard to line up, but I think you can see what I mean. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 23, 2009 Share Posted August 23, 2009 What you'll want to do is align the text to the right. Then add a bit of padding to the right side of the cell to move the text nearer to the center. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 23, 2009 Author Share Posted August 23, 2009 That's a good idea! Thank you! 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.