Asp. NET Convert RMB size amount

Source: Internet
Author: User

public class DECIMALTORMB
{
<summary>
Convert Renminbi size amount
</summary>
<param name= "num" > Amount </param>
<returns> return to uppercase form </returns>
public static string Cmycurd (decimal num)
{
String str1 = "0 One and three Woolu qi Ba Jiu"; 0-9 the corresponding Chinese characters
String str2 = "thousand thousand hundred million thousand to pick up million thousand hundred yuan angle cent"; Chinese characters corresponding to digit digits
String str3 = ""; Value taken from the original NUM value
String STR4 = ""; The string form of a number
String STR5 = ""; RMB Capitalization amount Form
int i; Loop variable
Int J; The value of num multiplied by the string length of 100
String ch1 = ""; The Chinese reading method of numbers
String CH2 = ""; The Chinese character reading method of digit digit
int Nzero = 0; To calculate a continuous 0 value is a few
int temp; Value taken from the original NUM value

num = Math.Round (math.abs (num), 2); Takes num absolute value and rounds it to 2 decimal places
STR4 = ((long) (NUM * 100)).        ToString (); Multiply num by 100 and convert to string form
j = Str4.      Length; Find the highest bit
if (J >) {return "overflow";}
STR2 = str2.   Substring (15-J); Remove the value of the str2 corresponding to the number of digits. such as: 200.55,j is 5, so str2= bai yuan angle points

Loop out the values that each bit needs to be converted
for (i = 0; i < J; i++)
{
STR3 = Str4.          Substring (i, 1); Remove the value of a bit to be converted
temp = Convert.ToInt32 (STR3); Convert to Digital
if (i! = (j-3) && i! = (j-7) && i! = (j-11) && i! = (j-15))
{
When the number of digits is not the number of yuan, million, billion, trillion
if (STR3 = = "0")
{
CH1 = "";
CH2 = "";
Nzero = Nzero + 1;
}
Else
{
if (str3! = "0" && Nzero! = 0)
{
CH1 = "0" + str1. Substring (TEMP * 1, 1);
CH2 = str2. Substring (i, 1);
Nzero = 0;
}
Else
{
CH1 = str1. Substring (TEMP * 1, 1);
CH2 = str2. Substring (i, 1);
Nzero = 0;
}
}
}
Else
{
This bit is a trillion, million, million, yuan and other key bits
if (str3! = "0" && Nzero! = 0)
{
CH1 = "0" + str1. Substring (TEMP * 1, 1);
CH2 = str2. Substring (i, 1);
Nzero = 0;
}
Else
{
if (str3! = "0" && Nzero = = 0)
{
CH1 = str1. Substring (TEMP * 1, 1);
CH2 = str2. Substring (i, 1);
Nzero = 0;
}
Else
{
if (STR3 = = "0" && Nzero >= 3)
{
CH1 = "";
CH2 = "";
Nzero = Nzero + 1;
}
Else
{
if (J >= 11)
{
CH1 = "";
Nzero = Nzero + 1;
}
Else
{
CH1 = "";
CH2 = str2. Substring (i, 1);
Nzero = Nzero + 1;
}
}
}
}
}
if (i = = (j-11) | | i = = (j-3))
{
If the bit is an million-bit or meta-bit, you must write the
CH2 = str2. Substring (i, 1);
}
STR5 = STR5 + ch1 + CH2;

if (i = = j-1 && STR3 = = "0")
{
The last one (minutes) is 0 o'clock, plus "whole"
STR5 = Str5 + ' whole ';
}
}
if (num = = 0)
{
STR5 = "0 yuan whole";
}
return STR5;
}

/**/
<summary>
An overload that converts the string first to a number in the call Cmycurd (decimal num)
</summary>
<param name= "num" > User input Amount, string form not turned into decimal</param>
<returns></returns>
public static string Cmycurd (String numstr)
{
Try
{
Decimal num = Convert.todecimal (NUMSTR);
return Cmycurd (num);
}
Catch
{
Return "non-digital form! ";
}
}
}
}

Asp. NET Convert RMB size amount

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.