在数字中添加逗号

时间:2015-10-23 06:06:36

标签: php mysql

<html> <head>   <title>Rough Diamond 
 Information</title> </head> 
<body>

<?php

mysql_connect("localhost","root","");
mysql_select_db("basic");
$order = "select * from calculator ";
$result=mysql_query($order);

echo "Rough Diamonds Information:&nbsp; &nbsp; &nbsp; &nbsp;";
echo "<a href='home.html'>Go to main page <br><br>";
?>


<table border="1" style="width:50%">
<tr>
    <th><b>ID</b></th>
    <th><b> Name</b></th>
    <th><b> Total Rough Weight</b></th>
    <th><b>One Carat Price</b></th>
    <th><b>Dollar Rate</b></th>
    <th><b>Payment Days</b></th>
    <th><b>Total Payment</b></th>
</tr>

<?php while($row = mysql_fetch_array($result) ) {

echo "<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['total_wt']."</td>
<td>".$row['crt_price']."</td>
<td>".$row['dollar_rate']."</td>
<td>".$row['pay_day']."</td>
<td>".$row['total_price']."</td>
</tr>";} ?>

</body>
</html>

4 个答案:

答案 0 :(得分:2)

使用number_format($number);

查看http://php.net/manual/en/function.number-format.php

答案 1 :(得分:1)

使用money_format格式化这样的货币。

$amount = '300000';
setlocale(LC_MONETARY, 'en_IN');
$amount = money_format('%!i', $amount);
echo $amount; // 3,00,000.00

以下是帮助链接Link

答案 2 :(得分:1)

number_format将适合您

number_format($row['number'],0);

答案 3 :(得分:0)

创建一个函数并显示如下数字

function moneyFormatIndia($num){
    $explrestunits = "" ;
    if(strlen($num)>3){
        $lastthree = substr($num, strlen($num)-3, strlen($num));
        $restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits
        $restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
        $expunit = str_split($restunits, 2);
        for($i=0; $i<sizeof($expunit); $i++){
            // creates each of the 2's group and adds a comma to the end
            if($i==0)
            {
                $explrestunits .= (int)$expunit[$i].","; // if is first value , convert into integer
            }else{
                $explrestunits .= $expunit[$i].",";
            }
        }
        $thecash = $explrestunits.$lastthree;
    } else {
        $thecash = $num;
    }
    return $thecash; // writes the final format where $currency is the currency symbol.
}

<?php while($row = mysql_fetch_array($result) ) {

echo "<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['total_wt']."</td>
<td>".$row['crt_price']."</td>
<td>".$row['dollar_rate']."</td>
<td>".$row['pay_day']."</td>
<td>".moneyFormatIndia($row['total_price'])."</td>
</tr>";} ?>