Decimal point alignment in a table - Page 2

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: Decimal point alignment in a table

On Mon, 9 Feb 2015 20:38:14 +0000, Dr J R Stockton wrote:
Quoted text here. Click to load it

You can use preformatted text for the values with monospace font using
non-breaking spaces at start of each values. Preformat it either from the
server side script (e.g. PHP) or JavaScript. When there are large number of
values to process, it's faster using server side script, but it burders the
server processing time.

If you're expecting 4 integer digits part of the values (e.g. 123456.12),
use 4 characters as the "aligning width". If the values can be negative,
increase the aligning width by 1 character. Use the aligning width and the
number of significant digits of each values to get the number of characters
needed for inserting the non-breaking space characters.

The result of the HTML code should be like below for 3 digits alignment

    td { font-family: monospace; }
  <table border=1>

That was based on left alignment. You can use right alignment based on the
number of fractional digits part of the values. This would be simpler
because you don't have to bother about the negative sign.

The result of the HTML code should be like below for right alignment and 2
digits alignment width:

    td { text-align:right; font-family: monospace; }
  <table border=1>

To avoid having spaces before/after the values, you'll have to use the
highest number of integer/fractional digits of all of the values in the same
column, as the alignment width.

Site Timeline