以逗号分隔格式化价格 [英] Formatting price as comma separated

查看:216
本文介绍了以逗号分隔格式化价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我有像


256.23,200.33,89.33,133.45,
< blockquote>

我必须将这些值乘以千,然后将结果格式化为价格(以逗号分隔)

 
256.23 x 1000 = 256230我想把这个显示为256,230

200.33 x 1000 = 200330我想要这个200,330

89.33 x 1000 = 89330我想要这个as 89,330

目前我正在使用公式

  echoPrice is:$。$ price * 1000; 

但是如何格式化,我不知道。

解决方案

您正在寻找 number_format < a> function。

  $ price = 123456; 
echo number_format($ price);
//输出:123,456

该函数接受一个,两个或四个参数不是三个):

如果只给出一个参数,则数字将被格式化为无小数,但在每组数字之间使用逗号(,)。 p>

如果给出了两个参数,那么数字将被格式化为小数点前面带点(。)的小数点,以及每一组数字之间的逗号(,) 。

如果给出所有四个参数,数字将被格式化为十进制小数,dec_point代替小数点前的小数点(。),而不是千位代码(,)之间。

In my database I have values like

256.23, 200.33, 89.33, 133.45,

I have to multiply these values with thousand and then format the result as price(comma separated)

256.23 x 1000 = 256230            I want to show this as            256,230

200.33 x 1000 = 200330            I want this as                    200,330

89.33  x 1000 = 89330             I want this as                    89,330

Currently I am using formula

echo "Price is : $".$price*1000;

But how to format this, I've no idea.

You are looking for the number_format function.

$price=123456;
echo number_format($price);
// output: 123,456

This function accepts either one, two, or four parameters (not three):

If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands.

If two parameters are given, number will be formatted with decimals decimals with a dot (".") in front, and a comma (",") between every group of thousands.

If all four parameters are given, number will be formatted with decimals decimals, dec_point instead of a dot (".") before the decimals and thousands_sep instead of a comma (",") between every group of thousands.

这篇关于以逗号分隔格式化价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆