I have a number like $scope.numbers = 1234567
when i apply {{numbers| number : 0}}
then i got result like 1,234,567
but is this possible to get result like 12,34,567
Thanks in advance.
The number format emitted by the number filter can be changed by installing an angular locale, as described in https://docs.angularjs.org/guide/i18n
I assume the number format you want is supported by some of the Indian locales, but my knowledge of these is limited.
Related
I have a list of number like "123,459","561,79" from france region and I want to convert it into our normal US english numbering system. How can I do it in JS using locale?
function eArabic(x){
return x.toLocaleString('en-US',{ minimumFractionDigits:2,
maximumFractionDigits:2 });
}
Input : "123,345"
Output : "123,345"
Expected Output : 123.345
This doesn't looks good. Do you have any suggestion for this problem? I do not want to replace comma with '.' in order to solve this issue.
You’re passing in a string, not a Number object (which is what toLocaleString requires to produce a formatted number). Do you have the original number available?
If you don’t, then your best bet (assuming a standardised format for the original number strings) would be to convert them into normal numbers then reformat them. Assuming that your numbers are going to be formatted according to French standards (, as a decimal separator) then you could use a simple string replacement before creating your number object:
var frenchNumberString = '123,456';
var numberObject = new Number(frenchNumberString.replace(',', '.'));
Then pass numberObject into your formatting code.
My problem is occurs for some random reason most of the graphics library do not use the internalization of currencies so the values I am wanting to read and transfer to the graphs are already formatted using my local currency already tried in many ways to solve this and not I managed, however, to arrive at a possible and most probable solution it works this way:
1,00 | 1
10,00 | 10
500,00 | 500
5.000,00 | 5000
70.000,00 | 70000
900.000,00 | 900000
1.000.000,00 | 1000000
Especially when I set these values in strings I wanted to remove all semicolons and last two numbers in values below why if I just remove the commas the graph will only read as a value of 100 or 1000 for example:
1,00 => 1
10,00 => 10
And so on to any number that comes after comma must be removed and at the beginning only the points be removed...
A brief demonstration of how the result is on my chart:
http://jsfiddle.net/Qa2Tx/29/
If you know some way to format numbers of this work without touching the commas and dots of my local currency I will explode with joy but if you can only format as I mentioned above I will be extremely happy and thank you for two days I am trying to solve this :D
I made a small demo of what you can do. You can use the split() function to split on the ,. This will divide the value on to sides
10,00 => ['10','00']
And you can just target the first part afte the split
This is a demo for just one value
var value = '1.000,00';
console.log(value.split(',')[0]);
This demo also remove the . and turns the value to a number
var value = '1.000,00';
console.log(Number(value.split(',')[0].replace(/[^0-9]+/g,"")));
This demo represent an array of values
var arr = ['1,00',
'10,00',
'500,00',
'5.000,00',
'70.000,00',
'900.000,00',
'1.000.000,00']
arr.map(value => console.log(Number(value.split(',')[0].replace(/[^0-9]+/g,""))))
Hope this helps :)
In my Angular 2.0 app I get prices from webapi and i need to format them again for example :
This is what i get from webapi : 40260000 as a price and i need to format it to 40.260 HUF which is Hungarian currency.
I tried some solutions but it seems that i missed something for example :
console.log(this.flatOffer.Price.toLocaleString('hu-HU'));
or
console.log(new Intl.NumberFormat('hu-HU').format(this.flatOffer.Price));
I appreciate any hint.
If you're displaying the currency in a view, I would look into the Angular Currency Pipe.
Also look at the Angular Decimal Pipe to understand the second portion of formatting in the Currency Pipe.
You can pipe your expression similarily:
{{myCurrencyValue | currency:'HUF':false:'1.3-3'}}
Note: This may not be exactly what you want in terms of the decimal formatting, but it should give you a good idea as to how you can format the currency.
I am using Globalizejs to format Currency based on Logged-In user details in my application.
I don't want currency Symbol to be displayed when formatting is done using below code snippet:
Globalize.locale( "en" );
currencyFormatter = Globalize.currencyFormatter( "USD", {
maximumFractionDigits: 0,
});
currencyFormatter(parseInt(totalCost.amount));
which returns
$1,212,122,112 for amount: 1212122112
Is there any option similar to maximumFractionDigits to avoid the currency symbol ?
Short answer: Globalize.numberFormatter
Longer answer: Two benefits of using currency formatter is: (a) have the currency symbol properly formatted, and (b) have the appropriate number of fraction digits properly formatted; note that several currencies such as USD, EUR, have 2 fraction digits by default, but others like JPY have 0, there are different cases too.
The appropriate solution to customize the markup and style of a formatted output is to use parts Globalize.currencyToPartsFormatter: At the time we speak, this feature isn't implemented yet https://github.com/globalizejs/globalize/issues/679.
As a workaround, which should work fine for your specific use case (no currency symbol + integers only amount), using Globalize.numberFormatter should suffice.
I've figured out in the past that if I want a number 100000 to have commas then I just add .toLocaleString() to the angularJS variable. ie:
<span>{{variable.toLocaleString()}}</span>
Also, if want to limit the number of decimal places to a number 20.34343434 to lets say 2, then I would just add .toFixed(2). ie:
<span>{{variable.toFixed(2)}}</span>
Now I would like to do both. ie:
<span>{{variable.toFixed(2).toLocaleString()}}</span>
or
<span>{{variable.toLocaleString().toFixed(2)}}</span>
but neither seem to work. Maybe the solution to this has nothing to do with either function.
Question: How do I add commas and limit the amount of decimal places in a value using HTML and angularJS?
You can do this with a currency filter using an empty string for the currency symbol:
{{variable | currency:""}}
If you want to change the number of decimal places, you can specify it as an argument (default is 2):
{{variable | currency:"":3}}
If you insist on using function then you can use:
{{variable.toLocaleString("nu", {minimumFractionDigits: 2, maximumFractionDigits: 2})}}
This will take care of both commas/spaces (depending on locale) in integer digits as well as separator (. or ,) depending on locale.