Just another WordPress site
16 Oct
Last night I received a real brain twister of a question from @ganarce on my Twitter page. He wanted to know if there was a way to align data within a table using a decimal point “.”. Seemed like a fairly routine type of formatting (invoices, data etc.). Without massaging the data ahead of time to all have the same number of characters before or after the decimal point.

I went to the W3C to for an explanation on horizontal alignment. Ah ha! there it was. Easy enough:
col align=”char” char=”.”
Unfortunately there is little or no support for this attribute amongst the Browser community. I found a method using JQuery that seems to work with IE, FF and Chrome.
Happy formatting!
One Response for "Aligning data with a decimal point using JQuery"
@ganarce is here! Thanks a lot for your code Sean, we are trying to transform it to make it work using , we are currently working on jquery to make it happen.
We found a another good JS example as well:
http://krijnhoetmer.nl/stuff/javascript/table-align-char/
The code is a little bit older and does not use Jquery, but it does provide an option to align to comma (,) something that we need in this case ( the site is in spanish). I’m going to post the results when ready
Leave a reply