RMB uppercase conversion

xiaoxiao2021-03-06  40

Problem: Money related projects such as business sector, invoicing, checks, usually demand into capital, such as "圆". During programming, the general coins are Double. The method currently see: Write this method, because the method is not very well seen, the usual practice is to process one by one, and determine whether a certain Chinese character should be output by the lengthy Switch ... case structure. Generally speaking, overall The task is simple, but the code and design quality are unsatisfactory. The design method is as follows: I need to pay attention to the problem: 1. Each Arabic number can pass through a array '壹', '', '' .... Representation. 2. For numbers greater than 10,000 and greater than 100000000, '10,000', 'billion' words 3. For the middle of the middle continuous 0, the words of 'zero' are correct, but there are several different cases need to be handled 4. For a certain number of numbers, for example, the entire 10,000 segment is 0 - 100000101, the middle 0 how to appear 5. A horon processing, if there is no angle, there should be 'round intense 'The words of the integer, that is, only the angle, there should be no' round 'word design frame: 1. Transform the number into string processing, use Java, transform a Double type into a character The string type is very simple, call string.valueof (double_var) to get, but there is a problem, when your number is greater than 10 positions, it is Danyi, he will convert a string of scientific counting. The solution is to convert him into a plastic long. 2. Segment the number into an integer portion and the fractional portion separately, according to the above method, we surely multiply the double 100, after the two digits are the fractional part, the front is integer part Get long L = (long) (d * 100); string string strital = string.valueof (l); string head = str remote.substring (0, strval.length () - 2); // Integer String end = STRVAL .substring (Strval.Length () - 2); // Endata 3. We should divide the money into a section, every four, actually get a two-dimensional array, as follows: 佰 佰 '' '' $ 4 $ 3 $ 2 $ 10,000 $ 12 $ 6 $ 51 $ 12 $ 1 in which $ 1 represents the number of the number of the i-th position of this number, we don't actually set the two-dimensional array, we get the number of numbers, what to process What kind of representation is very simple, this way is often: set POS to represent a digital location, POS / 4 in that section, 10,000 paragraphs, billion.pos% 4 indicates a certain segment,仟,, picked up, due to superposition, there will be millions, millions, millions, etc., so this design is established. This implies a question is that our current handling maximum Thousands of billions, larger numbers are not appropriate to use this structure because there may be trillions. At this time, the recommended idea is to design them into a single-dimensional array structure, thus obtaining overlapping representation. 4. Cyclic processing During the process, we can be expected that zero problems are the most difficult solution. Because we can only have a representation, more people, when a certain is 0, 'zero' It can't still appear. So these issues are considering to get the following code. Code: (Java Description) Public Static String ChangeTobig (Double Value) {char [] hunit = {'picking', '', ''};

// During the location indicates char [] vunit = {'10,000', 'billion'}; // segment name represents char [] Digit = {'zero', '', '', '', ' ',' Wu ',' Lu ',' 柒 ',' 捌 ','}; // Digital Represents long midval = (long) (Value * 100); // Convert to shaping string valstr = String.Valueof (midval); // Transform into string string head = valstr.substring (0, valstr.length () - 2); // Take a number of String rail = valstr.substring (Valstr.Length () - 2); / / Take a small number

String prefix = "" "; // Integer part of the result string suffix =" "; // decimal part of the result // processing of the number of decimal points behind (rail.equals (" 00 ")) {// If the fraction 0 suffix = "whole";} else {suffix = DIGIT [rail.charat (0) - '0'] "angle" Digit [rail.charat (1) - '0'] "points"; / / Otherwise transform the angle} // Treat the number of CHAR [] chdig = head.tochararray (); // transform the integer part into a character array char ZERO = '0'; // flag '0' indicating the appearance Cross 0 byte zeroSernum = 0; // Continuous appearance of 0 times FOR (INT i = 0; I 0 && ZeroSernum <

4) {prefix = VUnit [VIDX-1]; zero = '0';} Continue;} zeroSernum = 0; // Continue 0 Clear IF (ZERO! = '0') {// If the flag is not 0, add, for example, Wan, what is prefix = zero; zero = '0';} prefix = DIGIT [chDIG [I] - '0']; // Transformation This number indicates if (idx> 0) prefix = HUNIT [IDX-1]; if (idx == 0 && vidx> 0) {prefix = VUnit [VIDX-1]; // Segment end position should be added to the paragraph, such as 10 million}} f (prefix.length ()> 0) prefix = 'circle'; // If the integer part exists, there is a circular word Return Prefix SUFFIX; // Returns correctly} Cao Xihua 2004/12/21

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

New Post(0)