在英语语言环境中,数字如下所示:111,111,222.00
因此千位分隔符是逗号,十进制分隔符是点。例如德语中的相同数字看起来像111.111.222,00
,因此将千位和十进制分隔符颠倒了。有没有一种方法可以根据语言环境找到千位分隔符?
我发现了https://angular.io/api/common/getLocaleNumberFormat getLocaleNumberFormat()
函数的角度,但是我找不到使用方法,因为它总是返回格式en
语言环境格式
我通常在我的app.module中设置全局语言环境。
App.Module.ts
import { registerLocaleData } from '@angular/common';
import localeHe from '@angular/common/locales/he';
registerLocaleData(localeHe, 'he');
@NgModule({ // ....
如Angular文档所述,您必须将语言环境作为getLocaleNumberFormat()
函数的第一个参数提供:
getLocaleNumberFormat(locale: string, type: NumberFormatStyle): string
参数:locale : string
要使用的语言环境格式规则的语言环境代码。type : NumberFormatStyle
要格式化的数值类型(例如,十进制或货币。)
如果提供正确的语言字符串,则格式应该可以。