简体   繁体   English

如何将数字=“ $ lowprice”格式化为货币

[英]How to format number = “$lowprice” to currency

How to format number = "$lowprice" to currency 如何将数字=“ $ lowprice”格式化为货币

$price_content .= '<span>';
if ($currency_sympol) $price_content .= get_post_meta($id,$wprs_prefix.'lowprice', TRUE);
$price_content .= '<sup>'.$currency_sympol.'</sup>';
$price_content .= '</span>';

To format a number as currency use the money_format() function. 要将数字格式化为货币,请使用money_format()函数。 ( Docs ) 文档

$lowprice = 1234.56;

// Italian national format with 2 decimals
setlocale(LC_MONETARY, 'it_IT');
echo money_format('%.2n', $lowprice) . "\n";
// Eu 1.234,56

Since the currency is derived from the server locale, you might need to change it (see sample). 由于货币是从服务器区域设置派生的,因此您可能需要更改它(请参见示例)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM