number format on Zend Currency - zend-framework

I am developing a site Zend based but I have the followin problem:
$currency = new Zend_Currency();
$currency->toCurrency(20, array('currency' => 'EUR','number_format' => '#0.#'));
Gives me 20,00 EUR but I need 20.00 EUR (that is why i set number_format), Any suggestion?

Try changing number_format to just format.
Excerpt from Zend_Currency Docs in reference to the options array('format' =>'#0.00'): format: Defines the format which
should be used for displaying numbers. This number-format includes for
example the thousand separator. You can either use a default format by
giving a locale identifier, or define the number-format manually. If
no format is set the locale from the Zend_Currency object will be
used.

Related

Get currency symbol from currency/country code

I have my app translated to different languages (https://pub.dev/packages/flutter_translate) and I also provide the option to select a specific currency (https://pub.dev/packages/country_currency_pickers):
first 2 options
When I select the currency I get this:
Now that everything is selected I need to update my currency and for that I can do:
NumberFormat.simpleCurrency(
locale: "en_GB",
).format(money);
Notice that I have en_GB which is what I'd need here to display pounds. For this example I get es from the language and GB from the currency but es_GB gets euros instead of pounds, which is what I'd need.
How can I get the country code from any of the previous parameters?
Can I pass something else to get the symbol like currencyCode for example?
You should use provide name in the constructor. https://api.flutter.dev/flutter/intl/NumberFormat/NumberFormat.simpleCurrency.html
If name is specified, the currency with that ISO 4217 name will be used. Otherwise we will use the default currency name for the current locale.
NumberFormat.simpleCurrency(
name: "GBP", //currencyCode
).format(money)

fat free framework template date formatting

I have a DateTime field in mysql. Using a .ini file with this code:
_dateformat = {0,date,custom,%m-%d-%Y}
I can change the printed format of MyDate depending on the loaded language .ini by using this in my template:
{{#_dateformat,strtotime(#MyDate) |format}}
I'm now trying to find a way to display only the full month name from that date.
I tried these options (looking at the ICU-project specs)
_monthname = {0,date,custom,%M} (up to four M's)
_monthname = {0,date,custom,%L} (up to four L's)
_monthname = {0,date,custom,%F} (displays the date in yyyy-mm-dd format)
But nothing returns the month name.
How can I display only the month name of a date, language specific, in fat free framework using the template engine?

How i can get internationalized date string from Zend_Date without time

I need to echo internationalized time in different format for different languages.
Now i am using locale when creating a date, but it also outputs time:
$date->toString();
29.05.2012 0:00:00
Expected result:
29.05.2012
In documentation i can see inly custom formats (as i understand no internationalization format will be applied if i use them). Is it possible to output only date, without time, like described there (as i understand zf supports international formats: http://en.wikipedia.org/wiki/Date_format_by_country)?
I tried:
echo $date->get(Zend_Date::DATE_SHORT, $locale);
echo $date->toString(Zend_Date::DATE_SHORT); ?>
// produces MMMMMMMM (letters instead of date? Oo)
It didn't work because it was necessary to add
Zend_Date::setOptions(array('format_type' => 'iso'));
in bootstrap instead of
Zend_Date::setOptions(array('format_type' => 'php'));
With this option, it works fine!

Yii global date format (l18n)

When I type:
Yii::app()->getLocale()->dateFormat
it gives me the correct dateformat for the current set language. (in my example it is 'de' => dd.MM.yyyy). But when I type:
Yii::app()->format->dateFormat
Yii gives me the date format for 'en_us' (Y/m/d).
With getLocale() I will get only the string saved in i18n file. In ->format->date() this format string should be used, but I don't find a way to assign the i18n string to the CDateFormatter or CFormatter Object.
The CFormatter component accessed with Yii::app()->format is not meant to be used for localization out of the box; it does not automatically work according to the application locale.
You could manually change the relevant properties on Yii::app()->format to bring it in line with the application locale, but there is a more convenient way to format dates:
Yii::app()->locale->dateFormatter->formatDateTime(...)
See CDateFormatter::formatDateTime for more information; if you want more control, there are other methods such as CDateFormatter::format available. Also keep in mind that CLocale::getNumberFormatter() is available to format numbers.

Customizing phone number or any other String for different Locales in GWT

I am trying to find the best route to get in some Custom formats I need. For example if I have a phone number 0803456765
In India it may be represented as +91 (080) 3456765
In US it may be 080-345-6765 and so on
I could keep the format in the properties file and based on locale I could pull the format and format the String. I could also have a Util class which does this for me after I identify the Locale.
But I think there might be a better route using NumberFormat. I guess NumberFormat automatically figures out the Locale and applies a certain Pattern to the String. Can I customize this pattern ? In the sense, can I tell GWT to use my Custom pattern for the US Locale
I know we can do this
// Custom format
value = 12345.6789;
formatted = NumberFormat.getFormat("000000.000000").format(value);
// prints 012345.678900 in the default locale
GWT.log("Formatted string is" + formatted, null);
but I don't want to specify my formatting pattern as in 'NumberFormat.getFormat("000000.000000")'. I want to override the default number formats of various Locales in GWT to achieve this. How do I do this ?
Don't roll your own. Google open sourced their library which you can leverage. It supports
Parsing/formatting/validating phone numbers for all countries/regions
of the world.