用不同语言的数字获取千位数字分隔符

问题描述 投票:0回答:2

在英语语言环境中,数字如下所示:111,111,222.00因此千位分隔符是逗号,十进制分隔符是点。例如德语中的相同数字看起来像111.111.222,00,因此将千位和十进制分隔符颠倒了。有没有一种方法可以根据语言环境找到千位分隔符?

我发现了https://angular.io/api/common/getLocaleNumberFormat getLocaleNumberFormat()函数的角度,但是我找不到使用方法,因为它总是返回格式en语言环境格式

javascript angular typescript
2个回答
0
投票

我通常在我的app.module中设置全局语言环境。

App.Module.ts

import { registerLocaleData } from '@angular/common';
import localeHe from '@angular/common/locales/he';

registerLocaleData(localeHe, 'he');

@NgModule({ // ....

Angular I18n docs


0
投票

如Angular文档所述,您必须将语言环境作为getLocaleNumberFormat()函数的第一个参数提供:

getLocaleNumberFormat(locale: string, type: NumberFormatStyle): string参数:locale : string要使用的语言环境格式规则的语言环境代码。type : NumberFormatStyle要格式化的数值类型(例如,十进制或货币。)

如果提供正确的语言字符串,则格式应该可以。

© www.soinside.com 2019 - 2024. All rights reserved.