0

我想用这样的空格分隔数字: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;
    }
}
4

1 回答 1

5

PHP 有它自己的功能:number_format()

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

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

number_format($number, 0, '.', ' ');
于 2013-02-11T21:49:52.980 回答