Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly align numbers enclosed in parentheses? [duplicate]

I want to align positive numbers and negative numbers enclosed in parentheses using CSS to achieve the following result:

 431,000
 (26,000)
  94,000
 (57,000)

Using text-align:right; on table cells returns the following result instead:

 431,000
(26,000)
  94,000
(57,000)

But this is imperfect.

Is there an easy way to do this in such a way that parentheses have not effect on the alignment.

I want to align the numbers so that commas are on top of each other.

Thanks!!

like image 731
Irfanullah Jan Avatar asked Dec 15 '13 04:12

Irfanullah Jan


1 Answers

Whatever language you choose, you need to test your string output to see if they are negative or positive. Add the brackets to the negatives and add a   to the end of your positives and still use your text-align: right; Use this if you are using a font where all characters are the exact width like a typewriter.

or add this for a perfect fit otherwise.

<span style="visibility: hidden;">)</span>

after, this is most likely better anyways.

like image 51
Denver William Avatar answered Oct 02 '22 23:10

Denver William