C# Int To Chinese
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
public static class IntExtension
{
private static string ToChineseWithinTenThousand(this int value)
{
if (value == 0)
return "零";
if (value < 0 || value >= 10000)
return "";
string result = "";
string[] numbers = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
string[] units = new string[] { "", "十", "百", "千" };
int cursor = 0;
while (value > 0)
{
int remainder = value % 10;
if(remainder != 0)
result = numbers[remainder] + units[cursor] + result;
else
result = numbers[remainder] + result;
cursor += 1;
value /= 10;
}
result = Regex.Replace(result, "零*零", "零");
result = Regex.Replace(result, "零$", "");
result = Regex.Replace(result, "^一十", "十");
return result;
}
public static string ToChinese(this int value)
{
if (value == 0)
return "零";
bool negative = value < 0;
if (negative)
value = -value;
string result = "";
string[] units = new string[] { "", "萬", "億" };
int cursor = 0;
while (value > 0)
{
int remainder = value % 10000;
if (remainder != 0)
{
result = ToChineseWithinTenThousand(remainder) + units[cursor] + result;
if (remainder < 1000 && remainder != value)
result = "零" + result;
}
cursor += 1;
value /= 10000;
}
if (negative)
result = "負" + result;
return result;
}
}
相關文章
- C# int與string轉化C#
- c# (int)double顯式轉化C#
- C# modbus RTU 中使用到的 ushort[] 轉 int 與 int 轉 ushort[]C#
- C#中的 int?是什麼意思C#
- C#可空型別,int可以為nullC#型別Null
- (int)a、&a、(int)&a、(int&)a的區別
- chinese input method in emacsMac
- int[] 、 list<int> 、 list<int>[] 的區別
- C# 中,(int),Int32.Parse() 和 Convert.toInt32() 三種方法有何區別C#
- C語言之int *f()、int(*f)()、int *a[]、int (*a)[] 區別小記C語言
- 【轉載】C#之int與Java之Integer的區別C#Java
- c# for(int i;i<3;i++)迴圈的執行次序C#
- Some Chinese Android Developers InformationAndroidDeveloperORM
- extern int a 和int a的區別
- MySQL int(11)及int(M)解析MySql
- 強制型別轉換(int)、(int&)和(int*)的區別型別
- C++ const int * ; int * constC++
- The Five Colors of Chinese Painting(陳潔)AI
- Again, a chinese char conversion problemAI
- [原創] How to show chinese character in Git StatusGit
- Source chinese sex pills herbsexenhancement.comProstatitisROS
- Mysql中 int(10)和int(11)的區別MySql
- EntityBean : 有一個方法: public int ejbFindByPrimary(int id){Bean
- TKMySQL中int?(10)?和?int?(11)?的區別zceMySql
- Int -> List | List -> Int _ CodingPark程式設計公園程式設計
- The above mentioned chinese sex pills nutritional vitamins would
- POJ 4048 Chinese Repeating Crossbow(線段相交)ROS
- VS編譯器基礎 int main(int argc,char* argv[])編譯AIGC
- 解決equal to 運算中 "Chinese_PRC_CI_AS" 和 "Chinese_PRC_CS_AS" 之間的排序規則衝突排序
- Swift Int to StringSwift
- java 字串轉intJava字串
- #define int Modint<11>
- mysql int(3)與int(10)的數值範圍相同嗎?MySql
- The Chinese Room的過去、現在和未來OOM
- chinese-typesetting:更好的中文文案排版
- 微軟推出中文學習AI助手Microsoft Learn Chinese微軟AIROS
- oracle全文索引之LEXER_2_CHINESE_LEXEROracle索引
- Unable to View Chinese Font When Using Tools>Copy FileView