javascript - en-IN 区域设置不适用于 Angular 货币管道

标签 javascript angular currency

来自Wikipedia:

The Indian numbering system uses separators differently from the international norm. Instead of grouping digits by threes as in the international system, It groups the rightmost three digits together (till the hundreds place) and thereafter groups by sets of two digits. One trillion would thus be written as 10,00,00,00,00,000.

JavaScript 的 toLocaleString 函数以 en-IN 语言环境的正确格式返回。

(123456789).toLocaleString('en-IN', {
    style: 'currency',
    currency: 'INR',
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
})  //  ₹ 12,34,56,789.00

但是 Angular 的货币管道不会为 en-IN 语言环境返回相同的输出。我需要创建自定义管道吗?

{{ 123456789 | currency : 'INR' : 'symbol': '1.2-2' : 'en-IN' }}
<!-- ₹123,456,789.00 -->

最佳答案

app.module.ts 中添加以下行启用印度数字格式。如果您想使用多个区域设置,还给出了示例。

import { registerLocaleData } from '@angular/common';

import localeIn from '@angular/common/locales/en-IN';
registerLocaleData(localeIn);

import localeAr from '@angular/common/locales/ar-EG';
registerLocaleData(localeAr);


<p>
  <!-- ₹ 12,34,56,789.00 -->
  {{ 123456789 | currency : 'INR' : 'symbol': '1.2-2' : 'en-IN' }}
  <br/>
  <!-- ‏د.إ.‏ 123,456,789.00 -->
  {{ 123456789 | currency : 'AED' : 'symbol': '1.2-2' : 'ar-EG' }}
</p>

关于javascript - en-IN 区域设置不适用于 Angular 货币管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51857723/

相关文章:

mysql - 针对货币格式化 SQL 语句

java - 在线考试网络申请

angular - matches.slice 不是一个函数 ng2-bootstrap typeahead

javascript - 如何在两个 ngFor 中获取有序索引?

angular - 如何在 ng-select 中自定义清除按钮?

java - 如何格式化货币金额中的小数点后两位?

javascript - 如何从 JavaScript 获取 HTTP 状态

javascript - 需要使用 javascript trim 表单中的所有元素

javascript - 如何为 Google Maps API directionService 使用现有标记而不是定义新标记?

android - 如何发送包含十进制 float (.)的USSD码?