This is a discussion on Help with printf within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I'm working on a very simple program to output some date in a table. The last column of the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm working on a very simple program to output some date in a table. The
last column of the table shows the prices of various items. I'd like all of these prices to line up at the decimal point. In light of that, the code for the last column looks something like this (I've simplified it for this example): printf("<td> $ %5.2f </td>", $price); When I do this, however, I don't actually get the desired results. I do get 2 digits of decimal precision, but I do not get an overall field width of 5. What I wind up with is a column that looks like this: $ 5.25 $ .10 $ 19.25 Can anyone suggest a solution to this problem? I'm guessing (?) that this may have something to do with html ignoring white space in certain contexts, but I'm not sure if that's the case. More importantly, I'm not sure of an "easy" solution. Tony |
|
|||
|
Generally browsers ignore white space when rendering.
Here are two options. 1) use preformatting tags provided you use a mono-spaced font instead of a proportionally spaced- one this will preserve the spaces and line feeds (imagine the "b" represents a space character) <pre> bbbb$b5.25 bbbbb$b.10 bbb$b19.25 </pre> 2) use tables <table> <tr><td align='right'>$ 5.25 <tr><td align='right'>$ .10 <tr><td align='right'>$ 19.25 </table> Good Luck "Tony" <nospam@pittarese.com> wrote in message news:bv4h0r$glm@library2.airnews.net... > I'm working on a very simple program to output some date in a table. The > last column of the table shows the prices of various items. I'd like all of > these prices to line up at the decimal point. In light of that, the code > for the last column looks something like this (I've simplified it for this > example): > > printf("<td> $ %5.2f </td>", $price); > > When I do this, however, I don't actually get the desired results. I do get > 2 digits of decimal precision, but I do not get an overall field width of 5. > What I wind up with is a column that looks like this: > > $ 5.25 > $ .10 > $ 19.25 > > Can anyone suggest a solution to this problem? > > I'm guessing (?) that this may have something to do with html ignoring white > space in certain contexts, but I'm not sure if that's the case. More > importantly, I'm not sure of an "easy" solution. > > Tony > > |