From http://www.cnitblog.com/hj627/
"
Using System;
Using System. Collections. Generic;
Using System. text;
Namespace CW
{
Public Class Cash
{
Private Static String Moneynum = " " ;
Private Static String Moneyunit = " Million, billion " ;
Private Static String Cashunit = " Yuan Jiao Ming " ;
Private Static String [] Beforereplace = New String [] {Moneynum [ 0 ]. Tostring () + Moneynum [ 0 ]. Tostring (),
Moneyunit [ 7 ]. Tostring () + Moneynum [ 0 ]. Tostring () + Moneyunit [ 3 ]. Tostring (),
Moneynum [ 0 ]. Tostring () + Moneyunit [ 3 ]. Tostring (),
Moneynum [ 0 ]. Tostring () + Moneyunit [ 7 ]. Tostring (),
Moneyunit [ 7 ]. Tostring () + Moneyunit [ 3 ]. Tostring (),
Moneynum [ 0 ]. Tostring () + Moneynum [ 0 ]. Tostring (),
Moneynum [ 0 ]. Tostring () + Cashunit [ 1 ]. Tostring () + Moneynum [ 0 ]. Tostring () + Cashunit [ 2 ]. Tostring (),
Moneynum [ 0 ]. Tostring () + Cashunit [ 2 ]. Tostring ()
};
Private Static String [] Afterreplace = New String [] {Moneynum [ 0 ]. Tostring (),
Moneyunit [ 7 ]. Tostring () + Moneynum [ 0 ]. Tostring (),
Moneyunit [ 3 ]. Tostring () + Moneynum [ 0 ]. Tostring (),
Moneyunit [ 7 ]. Tostring () + Moneynum [ 0 ]. Tostring (),
Moneyunit [ 7 ]. Tostring () + Moneynum [ 0 ]. Tostring (),
Moneynum [ 0 ]. Tostring (),
String. empty,
String. Empty
};
/**/ /// <Summary>
/// String replacement method. The other is a recursive method based on four numbers.
/// Create by HJ 2007-10-21
/// </Summary>
/// <Param name = "moneynum"> </param>
/// <Returns> </returns>
Public Static String Getcash ( Decimal Moneynum)
{
String Intnum, point;
/**/ /// Integer
Intnum = Convert. tostring (math. Floor (moneynum ));
/**/ /// Decimal part
Point = Convert. tostring (math. Floor (moneynum * 100 ));
Point = Point. substring (point. Length - 2 );
/**/ /// Calculate integer
For ( Int I = 0 ; I < Moneynum. length; I ++ )
{
Intnum = Intnum. Replace (I. tostring (), moneynum [I]. tostring ());
}
Int Intnumlength = Intnum. length;
For ( Int I = Intnumlength - 1 ; I > 0 ; I -- )
{ /**/ /// Add Unit by number of digits
/// If the value is zero, no unit is added, but and need to be added.
If (Intnum [I - 1 ] = Moneynum [ 0 ] && (Intnumlength - I + 7 ) % 8 ! = 3 && (Intnumlength - I + 7 ) % 8 ! = 7 ) Continue ;
Intnum = Intnum. insert (I, moneyunit [(intnumlength - I + 7 ) % 8 ]. Tostring ());
}
/**/ /// Unit of plus angle and score
Intnum + = Cashunit [ 0 ]. Tostring () + Moneynum. substring (convert. toint16 (point [ 0 ]. Tostring ()), 1 ) + Cashunit [ 1 ]. Tostring () + Moneynum. substring (convert. toint16 (point [ 1 ]. Tostring ()), 1 ) + Cashunit [ 2 ]. Tostring ();
/**/ /// Replace zero-> 0 billion 0 thousand-> 0 thousand zero, 0 billion-> zero,-> zero,-> "", zero point-> "", zero point-> zero point, and then call it again to ensure the situation after replacement of 0 thousand million
For ( Int I = 0 ; I < Beforereplace. length; I ++ )
{
While (Intnum. indexof (beforereplace [I]) >- 1 )
{
Intnum = Intnum. Replace (beforereplace [I], afterreplace [I]);
}
}
/**/ /// Remove the last Zero
If (Intnum. endswith (moneynum [ 0 ]. Tostring () intnum = Intnum. substring ( 0 , Intnum. Length - 1 );
Return Intnum + Cashunit [ 3 ]. Tostring ();
}
}
}
"