如何将数字格式化

#1 cygsd

用find和findall读取数据后,怎样将其中的数字字段的输出进行格式化?
例如:将"1234567.89"格式化为"1,234,567.89"。
我知道,在sql中,可使用format(num,2)来实现。
请问在sp中如何实现?

2010-04-28 23:46:28

#2 hiramli

請使用PHP函數 number_format ,以下是例子

$number = 1234567.89;

$number_one = number_format($number); //輸出 : 1,234,567

$number_two = number_format($number,2); //輸出 : 1,234,567.89

2010-04-29 08:20:24

#3 jake

嗯,这里是number_format的文档 http://speedphp.com/doc/php/function.n/function.number-format.html

还有字符串处理的文档:http://speedphp.com/doc/php/r/ref.strings.html

2010-04-29 09:30:14

#4 redguan

我是放在模版中实现。一般不涉及计算。这样格式化显示数据,最好放在模版中。逻辑层保持原生数据。

模版引擎SMARTY是支持的,其它模版引擎不清楚了。

2010-04-29 11:44:34