Numerical alignment

Numerical alignment

badlerbadler Posts: 1Questions: 1Answers: 0

I'd like to use datatables to present some statistics. There will be multiple columns of numbers with a wide range of values, and I'm looking to align numbers in the same column horizontally, so their decimal point aligns. Essentially what's asked at https://stackoverflow.com/questions/1363239/:

I haven't seen any example showing support for this. Is this possible?

Thanks!
Ben

Answers

  • kthorngrenkthorngren Posts: 21,391Questions: 26Answers: 4,961

    I think that would be tough to workout a solution. See this thread. One option might be to use a number renderer and force all numbers to have the same number of decimal places. Might not work for your requirements though.

    Kevin

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 Site admin

    There was a specific CSS proposal to be able to do exactly this sort of things, but I'm damned if I can remember the name of it at the moment. It never got any traction and browser's didn't implement it.

    The way to do it is to split the number up - e.g.

    <span>123</span>
    <span>.</span>
    <span>4</span>
    

    Probably add some classes, then use CSS and flex box to align everything.

    It would be possible to wrap it up into a rendering function. That would be a good one for a blog post... I'll write that up once I've finished my current tasks (so probably towards the end Nov).

    Allan

Sign In or Register to comment.