的数字字符串中插入逗号

的数字字符串中插入逗号

我需要在表示货币的数字字符串中插入逗号和美元符号。使用网站代码或sqlcmd最好做到这一点,那会是什么样?

网页:

<div id='week'>
    <?php
        echo "<table>\n\n";

        $f = fopen("week.csv", "r");
        while (($line = fgetcsv($f)) !== false) {
                echo "<tr>";
                foreach ($line as $cell) {
                        echo "<td>Past Week:   $" . htmlspecialchars($cell) . "</td>";
                }
                echo "</tr>\n";
        }
        fclose($f);
        echo "\n</table>";
    ?>
</div>


CSS文件:

body {
    background-position:center;
    background-image: url(background.jpg);
    background-repeat: no-repeat;
}

#title {
margin-top:300px;
    font-size: 50px;
    text-align: center ;
    Font-family: Arial;
    color: white;
}

#week td {
    font-size: 30px;
    text-align: center ;
    Font-family: Arial;
    color: red;
}

 #week {
    border-color: white;
    height:50px;
    width:350;
    position:relative;
    margin-left: auto;
    margin-right: auto;
    margin-top:10px;


批处理文件:

sqlcmd -S myserver -U username -P password -d money -Q "declare @today datetime = '2014-5-21' set nocount on; select [Week Total] = (convert(varchar, convert(decimal(18, 2), sum([TotalJackpotAmount])), 3)) from [Accounting].[dbo].[HandPay] where [AccountingDate] <= @today and [AccountingDate] > dateadd(week, -1, @today);" -o \\location\to\write\file\Week.csv -h -1 -s ","


如果需要CSS,我也可以上传。

最佳答案

您可以使用number_format

foreach ($line as $cell) {
                        echo "<td>Past Week:   $" . number_format(htmlspecialchars($cell)) . "</td>";
                }

关于php - 如何在输入的数字字符串中插入逗号?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30379107/

10-09 17:03