Update:
Original:
Could you tell me why toLocaleString()
is not working here? It works in all other places. I need it to give 1000 separators
. Any clue or work around?
forEach(budgetList, async (b: Budget) => {
const budget: Budget = find(this.oldBudgetList, (budget: Budget) => {
return b.budgetGroup.name == budget.budgetGroup.name;
});
if (budget == null) {//new item
const log = this.logProvider.getLogDetails(`Budget : ${b.budgetGroup.name}`, `Added ${b.amount.toLocaleString()}`, 'project', project.id);
await this.logProvider.createLog(log, project.id);//add log
}
});
Runtime:
Another place and works well!
const log = this.logProvider.getLogDetails('Project : Budget', `Budget changed from ${this.oldBudgetValue.toLocaleString()} to ${project.budget.toLocaleString()}`, 'project', project.id);
await this.logProvider.createLog(log, project.id);//add log
The toLocaleString () method is a JavaScript method available for Number and Date type values. This method allows you to create a representation of the values in a locale-sensitive format. The locale values can be customized using the locales and options arguments to fit your requirements.
Most notably, the IE and Edge browsers insert bidirectional control characters around dates, so the output text will flow properly when concatenated with other text. For this reason, you cannot expect to be able to compare the results of toLocaleString () to a static value: Note: See also this StackOverflow thread for more details and examples.
Using number.toLocaleString ('fa') works perfectly in iOS but not in android. Sorry, something went wrong. Hi all, I am also experiencing this issue on android although it works fine in IOS.
The toLocaleString() method returns a string with a language-sensitive representation of this number. The source for this interactive example is stored in a GitHub repository. The compatibility table in this page is generated from structured data.
If the value is of type String
, you could do e.g.
Number(b.amount).toLocaleString()
(which was what was working in OP's case)
Other options could be
parseInt('number as string').toLocaleString()
parseFloat('number as string').toLocaleString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With