I'm trying to output columns of figures but they won't line up. It says in the tutorial I've got that fields are right-aligned by default; but my number fields are going silly. I'm getting the following...
My tutorial shows how to specify a field width for integers (I've checked that & everything lines up fine) and how to specify the number of decimal places for a floating point number. What it doesn't show, and I can't work out, is how to specify the TOTAL width of a floating point field with it right-aligned.
yes, but without the leading zeroes. I just want the figures right-aligned in a fixed-width field.
I'm trying to avoid tables. Apart from anything else if I do that I'll be dropping in & out of php all over the place & that would be a nightmare to follow.
You can try left padding the numbers with spaces ( ). It is not visible unlike a padded "0" but will serve the purpose.
I'm constructing the page from data held in a mySQL database so 90% is written in php. The other 10% is a Jscript form. Categories are selected in the form and I list all items, prices, discounts, and other data underneath. The data comes from various tables using joins. Using tables to display the data would be a pain in the butt. There aren't even a fixed number of columns as some categories of item have more than others, the visitor may be entitled to a discount in 1 category but not another, and various other parameters.
I could have 2 items with 3 columns, 1 item with 2 columns, the next with 4 and so on. I don't know how many columns there needs to be for any given item until I read the database; so I want to format each value as it's displayed according to how many columns there are for that item, not be constrained by a table layout where I have to have the max number of columns there could possibly be only to find that some of them aren't needed.
As I mentioned before, it says in my tutorial that fields are right-aligned by default but this doesn't seem to be the case in practice. If they were it would save me a lot of trouble.
You said you use intergers.
Then don't use %f, which is for floats, but %d for integers
I've got the whole thing wrapped in <pre></pre>