Digital to uppercase

Source: Internet
Author: User

Reprint: http://www.oschina.net/code/snippet_102306_4705

1.JS Implementation method

static string Converttochinese (Double x)
{
string s = x.tostring ("#L #e#d#c#k#e#d#c#j#e#d#c#i#e#d#c#h#e#d#c#g#e#d#c#f#e#d#c#.0b0a");
String d = Regex.Replace (S, @ "((? <=-|^) [^1-9]*) | ( (?‘ Z ' 0) [0a-e]* ((? =[1-9]) | (? ') -Z ' (? =[f-l\.]| $))))| ((?‘ B ' [f-l]) (? ') Z ' 0) [0a-l]* ((? =[1-9]) | (? ') -Z ' (? =[\.]| ($)))) "," ${b}${z} ");
Return Regex.Replace (D, ".", M + = "Negative yuan empty 0 a three-Woolu qi ba Shing empty empty empty points to pick up the hundred billion Beijing Gai trillion" [m.value[0]-'-']. ToString ());
}

2.c# Implementation method

private static String[] Ls_ShZ ={ "零" , "壹" , "贰" , "叁" , "肆" , "伍" , "陆" , "柒" , "捌" , "玖" , "拾" }; private static String[] Ls_DW_Zh ={ "元" , "拾" , "佰" , "仟" , "万" , "拾" , "佰" , "仟" , "亿" , "拾" , "佰" , "仟" , "万" }; private static String[] Num_DW ={ "" , "拾" , "佰" , "仟" , "万" , "拾" , "佰" , "仟" , "亿" , "拾" , "佰" , "仟" , "万" }; private static String[] Ls_DW_X ={ "角" , "分" }; /// <summary> /// 金额小写转中文大写。 /// 整数支持到万亿;小数部分支持到分(超过两位将进行Banker舍入法处理) /// </summary> /// <param name="Num">需要转换的双精度浮点数</param> /// <returns>转换后的字符串</returns> public static String NumGetStr(Double Num) {      Boolean iXSh_bool = false ; //是否含有小数,默认没有(0则视为没有)      Boolean iZhSh_bool = true ; //是否含有整数,默认有(0则视为没有)      string NumStr; //整个数字字符串      string NumStr_Zh; //整数部分      string NumSr_X = "" ; //小数部分      string NumStr_DQ; //当前的数字字符      string NumStr_R = "" ; //返回的字符串      Num = Math.Round(Num, 2); //四舍五入取两位      //各种非正常情况处理      if (Num < 0)          return "不转换欠条" ;      if (Num > 9999999999999.99)          return "很难想象谁会有这么多钱!" ;      if (Num == 0)          return Ls_ShZ[0];      //判断是否有整数      if (Num < 1.00)          iZhSh_bool = false ;      NumStr = Num.ToString();      NumStr_Zh = NumStr; //默认只有整数部分      if (NumStr_Zh.Contains( "." ))      { //分开整数与小数处理          NumStr_Zh = NumStr.Substring(0, NumStr.IndexOf( "." ));          NumSr_X = NumStr.Substring((NumStr.IndexOf( "." ) + 1), (NumStr.Length - NumStr.IndexOf( "." ) - 1));          iXSh_bool = true ;      }      if (NumSr_X == "" || int .Parse(NumSr_X) <= 0)      { //判断是否含有小数部分          iXSh_bool = false ;      }      if (iZhSh_bool)      { //整数部分处理          NumStr_Zh = Reversion_Str(NumStr_Zh); //反转字符串          for ( int a = 0; a < NumStr_Zh.Length; a++)          { //整数部分转换              NumStr_DQ = NumStr_Zh.Substring(a, 1);              if ( int .Parse(NumStr_DQ) != 0)                  NumStr_R = Ls_ShZ[ int .Parse(NumStr_DQ)] + Ls_DW_Zh[a] + NumStr_R;              else if (a == 0 || a == 4 || a == 8)              {                  if (NumStr_Zh.Length > 8 && a == 4)                      continue ;                  NumStr_R = Ls_DW_Zh[a] + NumStr_R;              }              else if ( int .Parse(NumStr_Zh.Substring(a - 1, 1)) != 0)                  NumStr_R = Ls_ShZ[ int .Parse(NumStr_DQ)] + NumStr_R;          }          if (!iXSh_bool)              return NumStr_R + "整" ;          //NumStr_R += "零";      }      for ( int b = 0; b < NumSr_X.Length; b++)      { //小数部分转换          NumStr_DQ = NumSr_X.Substring(b, 1);          if ( int .Parse(NumStr_DQ) != 0)              NumStr_R += Ls_ShZ[ int .Parse(NumStr_DQ)] + Ls_DW_X[b];          else if (b != 1 && iZhSh_bool)              NumStr_R += Ls_ShZ[ int .Parse(NumStr_DQ)];      }      return NumStr_R; }

Digital to uppercase

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.