| Revision 23494,
917 bytes
checked in by pineray, 12 years ago
(diff) |
|
#2386 PHP 警告撲滅 for 2.13.3
ロケール処理も考慮に入れて、Smartyの修飾子で対応するように変更.
|
| Line | |
|---|
| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * Smarty plugin
|
|---|
| 4 | * @package Smarty
|
|---|
| 5 | * @subpackage plugins
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | /**
|
|---|
| 10 | * Smarty n2s modifier plugin
|
|---|
| 11 | *
|
|---|
| 12 | * Type: modifier<br>
|
|---|
| 13 | * Name: n2s<br>
|
|---|
| 14 | * Purpose: formatting number to string.
|
|---|
| 15 | * @author pineray 松田光貴 <matsudaterutaka at gmail dot com>
|
|---|
| 16 | * @param string
|
|---|
| 17 | * @return string
|
|---|
| 18 | */
|
|---|
| 19 | function smarty_modifier_n2s($number)
|
|---|
| 20 | {
|
|---|
| 21 | $decimals = 0;
|
|---|
| 22 | $dec_point = ".";
|
|---|
| 23 | $thousands_sep = ",";
|
|---|
| 24 |
|
|---|
| 25 | // 引数を取得
|
|---|
| 26 | $args = func_get_args();
|
|---|
| 27 |
|
|---|
| 28 | // パラメーターの引数があればセットする
|
|---|
| 29 | if (count($args) > 1) {
|
|---|
| 30 | array_shift($args); // $number
|
|---|
| 31 | $decimals = $args[0];
|
|---|
| 32 | if (isset($args[1])) {
|
|---|
| 33 | $dec_point = $args[1];
|
|---|
| 34 | }
|
|---|
| 35 | if (isset($args[2])) {
|
|---|
| 36 | $thousands_sep = $args[2];
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | return number_format(floatval($number), $decimals, $dec_point, $thousands_sep);
|
|---|
| 41 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.