开发者

justify prices to right

I've some prices like £ 160.00, £ 14.0开发者_运维百科0,£ 7.00,£ 35.00........ I want to justify all prices to the right.How's it possible?


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...


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


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜