来自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/