如何将一串数字“12345678”格式化为“1,23,45,678”

How to format a string of numbers "12345678" to "1,23,45,678"

我需要像这样格式化我的号码 123456 至 1,23,456 1234567 至 1234567 12345678 至 1,23,45,678 123456789 至 12,34,56,789

我相信您正在寻找转换为印度计数格式的方法。

使用下面的代码格式化字符串

string.Format(new System.Globalization.CultureInfo("hi-IN"), "{0:#,#}", number)

使用上面的代码,输入数字的输出将是

string.Format(new System.Globalization.CultureInfo("hi-IN"), "{0:#,#}", 123456)
string.Format(new System.Globalization.CultureInfo("hi-IN"), "{0:#,#}", 1234567)
string.Format(new System.Globalization.CultureInfo("hi-IN"), "{0:#,#}", 12345678)


1,23,456


12,34,567


1,23,45,678

检查这个 dotnet fiddle - https://dotnetfiddle.net/TXQ09n