Getting a currency format pattern from AngularJS filter - angularjs

I'm interested in creating a filter that would accept an amount, ISO 4217 currency code, and fraction size, and return the amount in that format. I noticed that AngularJS has goog.i18n.currency.getGlobalCurrencyPattern in i18n/closure/currencySymbols.js, but I'm relatively new to Angular and not sure if it is possible to use it?

The currency pattern and symbols are just that. It determines how to display a number. It will not convert it from XXX to XXX. You will have to do the converting part based on the current conversion rates.
As far as using the built-in currency formatting, there are multiple ways: in the template, in the code.
In the template:
<div>{{myCurrencyValue | currency:'XXX'}}</div>
In the code:
var formatted = $filter('currency')(myCurrencyValue, 'XXX')
In both cases, 'XXX' is optional [and is symbol] and will use the default currency for current locale
Example: http://jsfiddle.net/TheSharpieOne/N7YuP/
More information can be found here: Currency Docs
UPDATE
Example with ISO 4217 codes using custom filter: http://jsfiddle.net/TheSharpieOne/N7YuP/3/
Note: ISO 4217 doesn't dictate the currency symbols, I used this for symbol reference and mapped them.

Related

Add separator text to Angular JSON data output in view

not sure I have asked the question correctly, the essence of what I need to do is in my view where I have specified for eg {{car.price}}, add a space as a thousands separator.
Not sure more info can be provided but I am more than willing to supply any that is needed.
you can use currency filter that is available in angularjs
just add this line in your code
{{ car.price| currency }}
use currency filter
{{ currency_expression | currency : symbol : fractionSize}}
or JS
$filter('currency')(amount, symbol, fractionSize)
for example:
{{car.price | currency:"₹":0}}
fractionSize is Number of decimal places to round the amount.

Localizing a currency range

A combination of formatjs & javascript's native Intl.NumberFormat() supports formatting of numbers as currency in various cultures and units. But how can I format a range of currency as $1,000.00 - 5000.00.
Without repeating the symbol, where ever and however it is normally displayed?
Using react-intl:
<FormattedNumber value={minVal} style="currency" currency="USD" />
- <FormattedNumber value={maxVal} style="currency" currency="USD" />
This will show $1,000.00 - $5000.00 which does not match my design spec. Stripping away the currency symbol off of the second value seems like a hackey strategy since I shouldn't/can't easily know the symbol to strip.
Formatting just as a regular decimal would be strictly incorrect - currency rules dictate different numbers of digits for the "minor units" depending on the currency.
And what about if the currency symbol is, I don't know, displayed at the end for the culture instead of at the beginning? (Does that happen?)
How about something like numeral.js? The locales documentation seems like it could do what you're looking for. They have a number of locales already and are happy to welcome more as contributions.
Update: looks like someone already created an Angular integration too.

How to add a space after currency symbol in CakePHP (3.0)?

The question is actually pretty simple. I have the following code to display my currency on my page. $this->Number->currency($HdViewBestellingen->INKBLPRIJS, 'EUR') This prints out the curreny like:
€0.12
But I want the currency to print out like:
€ 0.12
(notice the space between the € symbol and the number).
My question is, how do I achieve this using the CakePHP number formatter?
After reading http://book.cakephp.org/3.0/en/core-libraries/number.html#formatting-currency-values.
I have been messing around with the options array which can be passed as well like $this->Number->currency($HdViewBestellingen->INKBLPRIJS, 'EUR', ['pattern' => '#, ####.##']) but I couldn't get it to work.
It depends on the locale you are using. The locale also controls the position of the symbol.
If you use en_US then there are no spaces between the symbol and the number.
I suggest you to use any of the european locale. If you don't want to change it at application level in bootstrap.php you can set it just for one occurence like so
$this->Number->currency($HdViewBestellingen->INKBLPRIJS,'EUR', ['locale' => 'it_IT'])
I used italian locale because if you use german locale the euro symbol comes after the number

Adding new date formats to ExtJS

Ext.Date contains formats a and A for am/pm or AM/PM, respectively.
I want to add a format, call it b, for a/p without the m. I have searched parseFunctions and formatFunctions but did not find where the old format is defined.
Can anyone shed some light on this matter?
Have a look at formatCodes in Ext.Date:
The base format-code to formatting-function hashmap used by the format
method. Formatting functions are strings (or functions which return
strings) which will return the appropriate value when evaluated in the
context of the Date object from which the format method is called. Add
to / override these mappings for custom date formatting.

DevExpress XtraReport currency thousand separator

I have XtraReport with XtraLabel in detail band for display currency, ex: I have 2000000 and want to display it as 2.000.000, how can I do it?
You can do this by setting the FormatString property of 'Text` data binding as below.
xrLabel.DataBindings["Text"].FormatString = "{0:C}";
you can set refer Standard Numeric Format Strings and Custom Numeric Format Strings to specify format string that you want to apply.
References:
Formatting numeric values as Currency for an XrLabel
XRLabel - Setting FormatString during Report Generation

Resources