在英语语言环境中,数字看起来像这样:111,111,222.00
所以千位分隔符是一个逗号,小数点分隔符是一个点。例如在德语中,相同的数字看起来像 111.111.222,00
,因此千位分隔符和小数点分隔符颠倒了。有没有办法根据语言环境找到千位分隔符?
我找到了 https://angular.io/api/common/getLocaleNumberFormat getLocaleNumberFormat()
Angular 函数,但我找不到如何使用它,因为它总是返回格式 en
locale format
最佳答案
getLocaleNumberSymbol(语言环境:字符串,符号:NumberSymbol):字符串
import { getLocaleNumberSymbol, NumberSymbol } from '@angular/common';
// returns thousands sepator, comma (,) in this case:
getLocaleNumberSymbol('en-US', NumberSymbol.CurrencyGroup)
// returns decimal separator, dot (.) in this case:
getLocaleNumberSymbol('en-US', NumberSymbol.CurrencyDecimal)
如果区域设置数据不同于 en-US
,您应该将区域设置数据导入 AppModule
:
import '@angular/common/locales/global/en-GB';
@NgModule({...})
export class AppModule {
}
可在此处找到可用语言环境列表: https://github.com/angular/angular/tree/master/packages/common/locales
关于javascript - 获取不同语言 Angular 中数字的千位分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59607822/