C # Implementation, C + + to convert Arabic amount to Chinese capital amount

Source: Internet
Author: User

--------Number Conversion Capital function---------//
A function to convert a digital amount into a Chinese capital number
function Changenummoneytochinese (Money)
{
var cnnums = new Array ("0", "one", "II", "three", "premises", "WU", "Lu", "Qi", "ba", "JIU"); Number of Chinese characters
var cnintradice = new Array ("", "Pick", "Bai", "thousand"); Unit
var cnintunits = new Array ("", "Million", "billion", "Mega"); Corresponding integer part expansion unit
var cndecunits = new Array ("Angle", "min", "mm", "CL"); Corresponds to fractional part units
var Cninteger = "whole"; Character followed by integer amount
var cnintlast = "Yuan"; Units after completion of the integer type
var maxnum = 999999999999999.9999; Maximum number of processed
var integernum; Amount of the whole number of parts
var decimalnum; Amount of small part
var chinesestr = ""; Chinese amount string for output
var parts; Array used after separating amount, pre-defined
if (Money = = "") {
Return "";
}
Money = parsefloat (money);
if (Money >= maxnum) {
Alert (' exceeds maximum processing number ');
Return "";
}
if (Money = = 0) {
Chinesestr = Cnnums[0] + cnintlast + cninteger;
return chinesestr;
}
Money = money.tostring (); Convert to String
if (Money.indexof (".") = = =-1) {
Integernum = money;
Decimalnum = ";
} else {
Parts = Money.split (".");
Integernum = Parts[0];
Decimalnum = Parts[1].substr (0, 4);
}
if (parseint (Integernum) > 0) {//Get integral type partial conversion
var zerocount = 0;
var intlen = integernum.length;
for (var i = 0; i < Intlen; i++) {
var n = integernum.substr (i, 1);
var p = intlen-i-1;
var q = P/4;
var m = p% 4;
if (n = = "0") {
zerocount++;
} else {
if (Zerocount > 0) {
Chinesestr + = Cnnums[0];
}
Zerocount = 0; Return to zero
Chinesestr + = Cnnums[parseint (n)] + cnintradice[m];
}
if (m = = 0 && Zerocount < 4) {
Chinesestr + = Cnintunits[q];
}
}
Chinesestr + = Cnintlast;
Integral part processing complete
}
if (decimalnum! = ") {//Decimal part
var declen = decimalnum.length;
for (var i = 0; i < Declen; i++) {
var n = decimalnum.substr (i, 1);
if (n! = ' 0 ') {
Chinesestr + = Cnnums[number (n)] + cndecunits[i];
}
}
}
if (chinesestr = = ") {
Chinesestr + = Cnnums[0] + cnintlast + cninteger;
} else if (Decimalnum = = ") {
Chinesestr + = Cninteger;
}
return chinesestr;
}

//----------------------------------------------------------------//

------------------------C + + implementation------------------------------//
//----------------------------------------------------------------//

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace Std;

String Convertmoneycaps (long double moneysum)
{
long int temp_i = (long int) moneysum; /**//* Integer Part */
float temp_f = moneysum-temp_i; /**//* small number of parts */
int digit = 0, I, J, K, Num_i;
String Money ("");
Char num[20], *p;
Char name[][3] = {"Yuan", "Pick Up", "Bai", "Thousand", "million", "billion"};
Char numchar[][3] = {"0", "one", "II", "three", "premises", "WU", "Lu", "Qi", "ba", "JIU"};
Ltoa (temp_i, NUM, 10); /**//* integer part converted to string after processing */
p = num;
digit = strlen (num); /**//* integer partial number of bits */
/**//*--------Processing Integer part start--------*/
for (i = 1; i <= digit; i + +)
{
K = (digit-i)% 4;
if (IsDigit (*p))
{
Num_i = *p & 0xF; /* Convert characters to numbers such as ' 0 '-0, ' 1 '-1*/
/**//*--------Convert numbers start---------*/
if (num_i)
{
Money = money+ Numchar[num_i];
}
Else
{
if (k && (* (p + 1) &0xf))
Money + = "0";
}
/**//*--------Convert Digital end-------*/
/**//*---------Add count unit start----*/
if (k)
{
if (num_i)
Money = money + name[k];
}
Else
{
j = digit-i;
if (j)
Money = money + NAME[J/4 + 3];
Else
Money + = "Yuan";
}
/**//*--------Add count unit end--------*/
p++;
}
Else
{
Money = "encountered non-digital exit!";
return money;
}
}
/**//*--------Processing Integer part End--------*/
/**//*--------Processing of the decimal point start--------*/
if (Temp_f > 0.01)
{
if ((int) (TEMP_F*10)) money = money + numchar[(int) (TEMP_F*10)] + "Corner";
if ((int) (TEMP_F*100)%10) money = money + numchar[(int) (TEMP_F*100)%10] + "min";
}
/**//*--------Processing of decimal End--------*/
Money + = "whole";

return money;
}
int main ()
{
A long double x = 33.20;
cout << "Please input the money:";
CIN >> X;
cout << "Convert money Caps:";
String money = Convertmoneycaps (x);
cout << Money <<endl;
return 0;
}

C # Implementation, C + + to convert Arabic amount to Chinese capital 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.