1

I've some prices like £ 160.00, £ 14.00,£ 7.00,£ 35.00........ I want to justify all prices to the right.How's it possible?

Stoosh
  • 2,408
  • 2
  • 18
  • 24
Lucky13
  • 11,393
  • 7
  • 25
  • 36
  • 2
    Do you mean format them so they are left aligned? That's a CSS problem, simply encase them in a or
    and then give it the property "text-align: right".
    – shmeeps Feb 22 '11 at 04:24

4 Answers4

1

You need to give a bit more information as to what you are looking for, some examples, etc. I'm assuming you mean you want to align the pieces to the right, similar to the way numbers are in Excel, etc.

<table class="example">
    <tr>
        <th>Price 1</th>
        <td>£14.30</td>
    </tr>
    <tr>
        <th>Price 2</th>
        <td>£10.50</td>
    </tr>
</table>

And in your stylesheet:

.example td {
   text-align: right;
}

If this is what you were after, then this isn't really a PHP question...

Adam
  • 2,851
  • 1
  • 20
  • 20
0

This question was previously tagged PHP, so if the asker is still interested in a PHP option, here it is.

You can do this using a combination of <pre> tags and printf(). But css may be the preferable option.

<pre>
<?php foreach(array(1.5,10.5,132.25) as $price):?>
<?php printf("$%7.2f\n", $price);?>
<?php endforeach?>
</pre>

Produces:

$   1.50
$  10.50
$ 132.25
Jacob
  • 8,278
  • 1
  • 23
  • 29
0

Do you want something like this?

Ravioli                       $10
Spaghetti                     $9.99

If that's what you want, you can do it with this css:

.number {
    float: right;
}

and this html:

Ravioli <span class="number">$10</span>
<br>
Spaghetti <span class="number">$9.99</span>
tim
  • 43
  • 4
0

Aligning the decimal points. A simple CSS fix (though not extremely efficient)

ul { text-align:right; width:80px; }
li { list-style:none; }
i { float:left; }

<ul>
    <li><i>&pound;</i> 160.00</li>
    <li><i>&pound;</i> 14.00</li>
    <li><i>&pound;</i> 7.00</li>
    <li><i>&pound;</i> 35.00</li>
</ul>

Renders: Pounds to the left, Amounts to the right; however, relies on 2 decimal places after each pound/dollar amount.

Dawson
  • 7,567
  • 1
  • 26
  • 25
  • Previous SO post: http://stackoverflow.com/questions/1363239/aligning-decimal-points-in-html (Uses ``,`tables` JavaScript) – Dawson Feb 22 '11 at 07:06