admin管理员组文章数量:1289517
In English locale the number looks like this: 111,111,222.00
so thousand separator is a ma and decimal separator is a point. In e.g. German the same number looks like 111.111.222,00
so thousand and decimal separator are reversed. Is there a way to find a thousand separator based on locale?
I found getLocaleNumberFormat()
function in angular, but I couldn't find how to use it as it always return format en
locale format
In English locale the number looks like this: 111,111,222.00
so thousand separator is a ma and decimal separator is a point. In e.g. German the same number looks like 111.111.222,00
so thousand and decimal separator are reversed. Is there a way to find a thousand separator based on locale?
I found https://angular.io/api/mon/getLocaleNumberFormat getLocaleNumberFormat()
function in angular, but I couldn't find how to use it as it always return format en
locale format
3 Answers
Reset to default 7Use getLocaleNumberSymbol().
getLocaleNumberSymbol(locale: string, symbol: NumberSymbol): string
import { getLocaleNumberSymbol, NumberSymbol } from '@angular/mon';
// returns thousands sepator, ma (,) in this case:
getLocaleNumberSymbol('en-US', NumberSymbol.CurrencyGroup)
// returns decimal separator, dot (.) in this case:
getLocaleNumberSymbol('en-US', NumberSymbol.CurrencyDecimal)
You should import your locale data into the AppModule
if it's different from en-US
:
import '@angular/mon/locales/global/en-GB';
@NgModule({...})
export class AppModule {
}
List of available locales can be found here: https://github./angular/angular/tree/master/packages/mon/locales
I usually set global locale in my app.module.
App.Module.ts
import { registerLocaleData } from '@angular/mon';
import localeHe from '@angular/mon/locales/he';
registerLocaleData(localeHe, 'he');
@NgModule({ // ....
Angular I18n docs
As the Angular documentation says, you have to provide the locale as first argument to the getLocaleNumberFormat()
function:
getLocaleNumberFormat(locale: string, type: NumberFormatStyle): string
Parameters:
locale : string
A locale code for the locale format rules to use.
type : NumberFormatStyle
The type of numeric value to be formatted (such as Decimal or Currency.)
If you provide the correct language string, the formatting should work.
本文标签: javascriptGet thousand separator of numbers in different languages AngularStack Overflow
版权声明:本文标题:javascript - Get thousand separator of numbers in different languages Angular - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741461479a2380063.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论