PHP/Mysql 数字格式化

标签 php mysql

我试图让我的输出在数字中显示为逗号。我确信我很愚蠢,但我想不出如何让它发挥作用。我只是想格式化价格的数字输出。

    echo "</tr></table><br>";
    echo mysql_result($result,$i,"shortdescription")."<br><br>";

        echo "<div style=\"background-color:#FDFFDB\">";
        echo "<table border=1 cellpadding=5>";
        echo "<tr>";
        echo "<td class=txt width=200><b>Price low season</b><br><i>May 15th - Nov 30th</i></td>";
        echo "<td class=txt width=200><b>Price high season</b><br><i>Dec 1st - May 14th</i></td>";
        echo "<td class=txt width=200><b>Xmas, New Year &<br>Sailing regattas</b></td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td class=txt>US$ ".mysql_result($result,$i,"pricelownight")." per night</td>";
        echo "<td class=txt>US$ ".mysql_result($result,$i,"pricehighnight")." per night</td>";
    if (mysql_result($result,$i,"pricespecial")){
        echo "<td rowspan=2 class=txt>US$ ".mysql_result($result,$i,"pricespecial")." per week</td>";
    } else {
        echo "<td rowspan=2 class=txt>Price upon request</td>";
    }

最佳答案

直接来自来源:http://www.php.net/manual/en/function.money-format.php

$number = 1234.56;

// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
// USD 1,234.56

关于PHP/Mysql 数字格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23942353/

相关文章:

php - 如何: Dynamic 7 day forecast calendar loops - PHP, MySQL

php - 使用 PDO 更新数组

php - connect() to unix :/var/run/php/php7. 2-fpm.sock failed (11: 资源暂时不可用)

PHP Socket 服务器挂起

PHP MYSQL 上传文件并存储为 blob

php - 试图让 php 查询每天只发生一次

mysql - 在多个表上转储查询

mysql - 从表中获取一组输入的下一个最大时间

php - 购买后如何更新数据库中的用户?

c# - 循环参数化查询