Value to capitalization RMB - Java

xiaoxiao2021-03-05  25

Recently used in the value of the value into capitalization, I found only C version on the Internet, so it's easy to find a Java version of active charge! ! There is no way to get it out, I want to use the function of this feature is certain, I will take it out and share it! ! / ** *

Title: Money *

Description: * * This class is a class that converts the Arabic digital to Chinese capital. According to the C program of Wang Daqing, I have a C * * program with Wang Daqing brother, if there is any problem with the attached C program, please contact Wang Daqing's brother to email: Wang_daqing@21cn.com * * * * If there is anything about the Java section, please contact your younger brother, Yang Hao email: Netfalcon@263.net * * Class Name: Money * * Function: String PositiveIntegertohanstr (String Numstr) Converts the number in front of the decimal point to uppercase Chinese * * Function: String NumTORMBSTR (Double Val) is responsible for converting the input Double type to uppercase Chinese * * Note the range of Java program conversion is: 15 digits in front of the decimal point (pass), the C program is 24 bits (I don't have Test) * *

Copyright: Copyright (c) 2003 You can modify, copy, use this program, but please keep this annotation statement! ! ! *

Company: * @AUTHOR Wang Daqing, Yang Wei * @Version 1.0 * /

Import java.lang.math;

public class money {with the main function public static void main (String args []) {money mon = // when debugging new money (); System.out.println (-99999999999999.999 mon.NumToRMBStr (-99999999999999.999)); System. out.println (99999999999999.999 mon.NumToRMBStr (99999999999999.999)); System.out.println (mon.NumToRMBStr (100000000.00)); System.out.println (mon.NumToRMBStr (100000001.00));} String HanDigiStr [] = new String [] {"Zero", "", "", "", "", "Wu", "Lu", "柒", "捌", ""}

String HandiVistr [] = new string [] {"", "pick", "", "仟", "10,000", "", "仟", "100 million", "pick", " "" "," 10,000 "," pick "," "," 仟 "," 100 million "," "," "," 仟 "," 10,000 "," pick "," " , ""}; String Positiveintegertohanstr (String Numstr) {// Enter strings must be integrated, only the front guide felt (must be right), should not have preamble zero string rmbstr = ""; Boolean Lastzero = false; boolean Hasvalue = False; // billion, there is a numerical mark int LEN, N; N; Numstr.length (); if (len> 15) returno "value is too big!"; for (int i = len-1; i> = 0; I ---) {IF (Numstr.Charat (LEN-I-1) == ') Continue; N = Numstr.Charat (LEN-I-1) -' 0 '; if (n <0 | | n> 9) Return "Enter the non-numeric character!"; if (n! = 0) {if (Lastzero) RMBSTR = handigistr [0]; // If you follow the zero, only one zero / / In addition to hundreds of thousands of zero do not bring back // if (! (N == 1 && (i% 4) == 1 && (Lastzero || i == LEN-1)))) // There is no zero before zero, you don't send the sound (! (N == 1 && (i% 4) == 1 && i == len-1) // Ten-in-one in the first unmoving RMBSTR = Handigistr [N]; RMBSTR = Handivistr [i]; // Non-zero-added feed, one is empty Hasvalue = true; // 进 进 有 有 值 标}} else {IF ((i% 8 ) == 0 || ((i% 8) == 4 && h ASVALUE)) // billion must have a non-zero value to show Wan RMBSTR = Handivistr [i]; // "100 million" or "10,000"} = = = == 0) Hasvalue = false; // Wanjin prior value tags Harillion reset lastzero = (n == 0) && (i% 4! = 0);} if (rmbstr.length () == 0) Return Handigistr [0]; // Enter empty characters Or "0"

Returns "zero" RETURN RMBSTR;} String NumTORMBSTR (Double Val) {string SIGNSTR = ""; String Tailstr = "; Long Fraction, Integer; Int Jiao, Fen; IF (Val <0) {VAL = -Val; SIGNSTR = "Negative";} if (Val> 9999999999999999999999999999999999999.999999999999.999) Return "Numerical position is too big!"; // Since the round to the division long Temp = Math.Round (Val * 100); Integer = TEMP / 100; FRAction = Temp% 100; jiAO = (int) Fraction / 10; fen = (int) Fraction% 10; if (jiAo == 0 && fen == 0) {TAILSTR = "whole";} else {tailstr = Handigistr [jiao]; if (jiao! = 0) TAILSTR = "Corner"; if (Integer == 0 && jiao == 0) // 元 不 不 不 不 不 不 不 不 不 不 不 不 不 不 不 不 不 不 不 不 不= 0) TAILSTR = Handigistr [fen] "points";} // The next line can be used for informal financial situations, 0.03 only display "叁" rather than "zero yuan 叁" // if (! Integer) Return SIGNSTR TAILSTR; RETURN "¥" SIGNSTR POSTINTEGERTOHANSTR (String.Valueof (Integer) "Yuan" Tailstr;}} // End public class Money // Source program of King Daqing brother C source program: // RMB .cpp / *

#include // must define Ansistring Before Rmb.h # Pragma HDRSTOP / / ONLY for C Builder

#include #include "rmb.h"

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

// Constant string definition, such as modification can also become converted to ordinary Chinese characters (such as: one or two three, ten hundred) const char * handigistr [] = {"zero", "", "贰", "" "," "," Wu "," Lu "," 柒 "," 捌 "," 玖 "}

Const char * handivistr [] = {"", "pick", "", "仟", "10,000", "", "", "hundreds", "pick", "" "", "10,000", "pick", "", "", "", "10,000", "pick", "", "仟 "}; Ansistring PositiveIntegertohanstr (Const Ansistring & Numstr) {// Input strings must be integrated, only the front guide felt (must be right) 0; // billion, there are numeric tags before entering

Len = Numstr.length (); if (len> 24) return "is too big!";

For (int i = len-1; i> = 0; I -) {if (Numstr [len-i] == ') Continue; // Ansistring [] base is 1 n = numstr [len-i] - '0'; if (n <0 || n> 9) return "Enter the non-numeric character!";

IF (n! = 0) {if (Lastzero) Rmbstr = handigistr [0]; // If you follow the non-zero, only one zero // In addition to the zero of hundreds of millions of zero does not bring back // if (! (n == 1 && (i% 4) == 1 && (Lastzero || i == LEN-1))))))))) // If there is zero, there is no 壹 壹 壹 壹 壹 (i) ! (n == 1 && (i% 4) == 1 && i == len-1)) // Ten-in-one in the first position does not send 壹 Rmbstr = handigistr [N]; Rmbstr = Handivistr [i ]; // Non-zero value is added, the position is empty Hasvalue = 1; // 进 有 有 值 标}} else {IF ((i% 8) == 0 | ((i% 8) = = 4 && Hasvalue) // billion must have a non-zero-value side to display Wan RMBSTR = Handivistr [i]; // "100 million" or "10,000"} = 0) Hasvalue = 0 ;/ 复 复 l l 复 复 复;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 零 零

IF (RMBSTR.LENGTH () == 0) Return Handigistr [0]; // Enter empty characters or "0", return "zero" RETURN RMBSTR;} ANSISTRING NUMTORMBSTR (Double Val) {ANSISTRING SIGNSTR, TAILSTR; DOUBLE FRACTION, Int Jiao, Fen;

IF (Val <0) {val = -val; signstr = "negative";} fraction = modf (val 0.005, & integer); // Since the round

JIAO = INT (FRAction * 10); FEN = Int (Fraction * 100) -Jiao * 10; if (jiao == 0 && fen == 0) {TAILSTR = "whole";} else {tailstr = handigistr [jiao] ; If (jiao! = 0) TAILSTR = "Corner"; if (Integer == 0 && jiao == 0) // 元 元 不 不 t t t = = = = 元 元 元 = Handigistr [fen] Ansistring ("Minute");

// The next line can be used for informal financial situations, and 0.03 only shows "叁" rather than "zero-element" // if (integer == 0) Return SIGNSTR TAILSTR;

Return SIGNSTR POSTINTEGERTOHANSTR (Ansistring (Integer) "Yuan" TAILSTR;}

// below is RMB.H

#ifndef rmbh # Define RmbH

// for Ansistring Def // #include

// Value transfers the RMB function ANSISUSTRING NUMTORMBSTR (Double Val);

正 正 整 数 转转 函, does not recommend using // input strings must be integrated, only the front guide felt (must be right), should not have a preamble zeroH // Ansistring PositiveIntegertohanstr (const Ansistring & numstr);

#ENDIF

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

// Basic consideration /// RMB capital unit bank regulations use "yuan" // no zero amount of "whole", there is no way to zero when it is orthored (such as zero points) // / / In order to reduce the doubts of judgment (generally higher than the expectation of larger number of money) and // reflect the basic unit of RMB, the amount is less than the "zero" before the round.

// Integer conversion // Several zero after zero, only one zero, otherwise it will not zero zero before it is displayed // million (100 million), because of 100 million, Wan is a full unit, // (such as : Picking up thousands of thousands of 零 零 零 顺 顺) // billion is the largest unit of Chinese, as long as the carry is always displayed (eg, hundreds of millions of billion) // million, the maximum unit, hundreds of millions must There is a non-zero-value side to show that there is no (such as "100 million" cannot be displayed as "100 million") //// // to reduce the probability of being tampered, ten in total, the general, this and the following habit reading Different // (10 in the first place did not send the sound, such as "picking up" non-"拾 元", // Do not send a zero before the 10th place, do not send the sound is not sure, // If "零 壹 元 元 "or" 零 零 元 "?) // Use" pick up "without" 壹 万 万 ", because each integer is in carrying out the unit (万 万)) // this Even if there is no prefix, there is no prefix, such as "Renmin", which is to add two Chinese characters, and after the number of changes must be added, and the number must be entered. (If "picking thousand" can be changed " Pick up the "," 万 万 "is to change to" 壹 万 万 ") // This function is written for Borland C Builder, which has been fully taken into account with cross-platform compatibility // If you need to switch to other occasions, / / Simply modify string type from Ansistring to the corresponding type, function and function // (Note that two char * type strings can not be added directly, there is a first conversion)

// public domain freeware by Wang Daqing March 2003 V1.1 // This function please email: wang_daqing@21cn.com

* /

转载请注明原文地址:https://www.9cbs.com/read-33127.html

New Post(0)