【问题标题】:separate numbers with space用空格分隔数字
【发布时间】:2013-02-11 21:47:51
【问题描述】:

我想用这样的空格分隔数字:1 200,12 500 或 2 000 000 而是 2000000...

function show_price($id) {
    global $currency_a;
    if(get_option("defaultcurrency")) {
        $curr = $currency_a[get_option("defaultcurrency")][2];
    } else {
        $curr = $currency_a[get_post_meta($id, "currency", true)][2];
    }
    $price = get_post_meta($id, "price", true);
    $currpos = get_option("currpos");
    if($currpos == "1" || !$currpos) {
        return $price."".$curr;
    } elseif ($currpos == "2") {
        return $curr."".$price;
    } elseif ($currpos == "3") {
        return $price;
    }
}

【问题讨论】:

    标签: php numbers space


    【解决方案1】:

    PHP 有它自己的函数:number_format()

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

    只需将 $thousands_sep 参数设置为空白而不是默认值。例如:

    number_format($number, 0, '.', ' ');
    

    【讨论】:

    • 在添加货币之前添加它:$price = number_format(get_post_meta($id, "price", true),' ', ' '); 这仅格式化数字,如文档中所述(您应该阅读)。
    • 问题解决了!谢谢回答!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 2016-03-12
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多