如何在Dart中将数字格式化为数千个分隔符 [英] How to format numbers as thousands separators in Dart

查看:150
本文介绍了如何在Dart中将数字格式化为数千个分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将数字格式化为飞镖中的数千个分隔符.我有这样的数字:

I have to format numbers as thousands separators in dart. I have numbers like:

16987

13876

456786

,我想将它们格式化为:

and I want to format them as :

16,987

13,876 

4,56,786

推荐答案

您可以使用NumberFormat以ICU格式化模式传递自定义格式,请查看

You can use NumberFormat passing a custom format in ICU formatting pattern, take a look in NumberFormat.

import 'package:intl/intl.dart';

void main() {
  var formatter = NumberFormat('#,##,000');
  print(formatter.format(16987));
  print(formatter.format(13876));
  print(formatter.format(456786));
}

输出

16,987
13,876
4,56,786

这篇关于如何在Dart中将数字格式化为数千个分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆