In my PHP outputs, number shows 1,234.56
How can I change this to 1234,56 or 1.234,56?
What is the American way and European way?
Does php work with American way?
In my PHP outputs, number shows 1,234.56
How can I change this to 1234,56 or 1.234,56?
What is the American way and European way?
Does php work with American way?
Use number_format:
echo number_format($num, 2, ',', '.');
With the arguments being:
The european way varies regionally and can be one of these:
123.456,50
(eg. German)123,456.50
(eg. English)123 456,50
(eg. French)123'456,50
(eg. Swiss)The american way is 123,456.50
and yes, all formats work. It doesn't matter how you output them, PHP handles floats internally in 123456.50
format.
You can get the formate details for the current locale using localeconv (http://uk2.php.net/localeconv):
<?php
if (false !== setlocale(LC_ALL, 'nl_NL.UTF-8@euro')) {
$locale_info = localeconv();
print_r($locale_info);
}
?>
Which will give something like:
Array
(
[decimal_point] => .
[thousands_sep] =>
[int_curr_symbol] => EUR
[currency_symbol] => €
[mon_decimal_point] => ,
[mon_thousands_sep] =>
[positive_sign] =>
[negative_sign] => -
[int_frac_digits] => 2
[frac_digits] => 2
[p_cs_precedes] => 1
[p_sep_by_space] => 1
[n_cs_precedes] => 1
[n_sep_by_space] => 1
[p_sign_posn] => 1
[n_sign_posn] => 2
[grouping] => Array
(
)
[mon_grouping] => Array
(
[0] => 3
[1] => 3
)
)
Zend_Currency offers the following functions for handling currency manipulations:
* Complete Locale support: Zend_Currency works with all available locales and therefore knows about over 100 different localized currencies. This includes currency names, abbreviations, money signs and more.
* Reusable Currency Definitions: Zend_Currency does not include the value of the currency. This is the reason why its functionality is not included in Zend_Locale_Format. Zend_Currency has the advantage that already defined currency representations can be reused.
* Fluent Interface: Zend_Currency includes fluent interfaces where possible.
* Additional Methods: Zend_Currency includes additional methods that offer information about which regions a currency is used in or which currency is used in a specified region.
// creates an instance with 'en_US' using 'USD', which is the default
// values for 'en_US'
$currency = new Zend_Currency('en_US');
// prints '$ 1,000.00'
echo $currency->toCurrency(1000);
It is not exactly what you asked for, you just have to find a proper locale.