| | 150 | * Format number according to localization |
| | 151 | * |
| | 152 | * PHP native function number_format unfortunatelly does not support |
| | 153 | * decimal point or thousand separator longer than one character, e.g. |
| | 154 | * like |
| | 155 | * This function does support multi-char decimal point and thousands |
| | 156 | * separator. |
| | 157 | * Source code copied from http://www.php.net/number_format, comment |
| | 158 | * by team at glossword dot biz. Thank you! |
| | 159 | * |
| | 160 | * @param mixed $number The number to convert based on locale. |
| | 161 | * @param int $decimals Precision of the number of decimal places. |
| | 162 | * @param string $dec_point Decimal point string |
| | 163 | * @param string $thousands_sep Thousands separator |
| | 164 | * @return string Converted number in string format. |
| | 165 | */ |
| | 166 | function wp_number_format($n, $decimals = 0, $dec_point = '.', $thousands_sep = ',') |
| | 167 | { |
| | 168 | $b = explode('.', $n); |
| | 169 | $fract = sprintf('%0.'.$decimals.'f', '0.'.$b[1]); |
| | 170 | if ($fract[0] == '1') { |
| | 171 | $b[0] = $b[0] + ($b[0] >= 0 ? 1 : -1); |
| | 172 | $fract[0] = '0'; |
| | 173 | } |
| | 174 | $rn = ''; |
| | 175 | $l = strlen($b[0]); |
| | 176 | /* Reverse string */ |
| | 177 | for ($i = $l; $i > 3; $i -= 3) |
| | 178 | { |
| | 179 | $rn = $thousands_sep . substr($b[0], $i - 3, 3) . $rn; |
| | 180 | } |
| | 181 | /* sprintf() used to correct 0.79 to 0.790 */ |
| | 182 | /* str_replace() used to correct decimals */ |
| | 183 | /* str_repeat() used to correct decimals */ |
| | 184 | return substr($b[0], 0, $i) . $rn . ($decimals |
| | 185 | ? $dec_point.(isset($b[1]) |
| | 186 | ? str_replace('0.', '', $fract) |
| | 187 | : str_repeat(0, $decimals)) |
| | 188 | : ''); |
| | 189 | } |
| | 190 | |
| | 191 | /** |