我希望分隔符为1位,2位,3digit,4位,5位数 [英] I want separator the number for 1 digit, 2 digit, 3digit, 4digit, 5 digit

查看:75
本文介绍了我希望分隔符为1位,2位,3digit,4位,5位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的c#代码中试过这样的事情



int number = 1234567890

string value = string.Format({0 :#,### 0},数字);



所需:



12,3456 ,7890



实际:



1,234,567,890



我尝试过:



I have tried like this in my c# code

int number = 1234567890
string value = string.Format("{0:#,###0}", number);

Desired:

12,3456,7890

Actual:

1,234,567,890

What I have tried:

int number = 1234567890
string value = string.Format("{0:#,###0}", number);

推荐答案

虽然.NET支持数字分组,但它仅支持普通分组:3位数(西数字)和2位数字,初始3(印地语)。

我知道没有使用4位分组的系统:你必须自己编写。

这并不复杂:将值转换为没有分组的字符串,然后将字符串拆分为所需的组,并在需要的地方添加逗号。
Although .NET supports digit grouping, it only supports "normal" groupings: 3 digits (western numbers) and 2 digits with an initial 3 (Hindi).
I know of no system which uses 4 digit grouping: you will have to write your own.
That's not complex: convert the value to a string with no grouping, and then split the string into the groups you need, adding the commas where needed.


这篇关于我希望分隔符为1位,2位,3digit,4位,5位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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