Pen: amount conversion, the amount of Arabic numerals is converted into a traditional Chinese form, such as: (¥1011)-> (one thousand and one pick up one yuan) Output

Source: Internet
Author: User

The reason for collecting this question is that I have done it before, but it is very troublesome to implement it. This time, it is easy to understand what others wrote.

We can see from a PDF that the source is not pasted =. =

Public class Renmingbi {Private Static final char [] DATA = new char [] {'0', 'yi', 'er', 'san', 'Ta ', 'wo', 'loan', 'region'}; Private Static final char [] Units = new char [] {'meta ', 'pick', 'handler', 'handler', 'wan', 'handler ', 'clerk'}; // simple integer INT:-2147483648 ~ 2147483647 public static string convert (long money) {stringbuffer SBF = new stringbuffer (40); int unit = 0; while (money! = 0) {SBF. insert (0, units [unit ++]); int number = (INT) Money % 10; SBF. insert (0, data [number]); money/= 10;} // system. out. println (SBF. tostring (); Return SBF. tostring (). replaceall ("Zero [zhibai]", "zero "). replaceall ("0 + 1 million", "1 million "). replaceall ("Zero + ten thousand", "Ten Thousand "). replaceall ("Zero + RMB", "RMB "). replaceall ("Zero +", "zero "). replaceall ("", "");} // complex long with decimals:-2 ^ 63 + 2 ^ 63-1 public static string convert (double value) {long midval = (long) (value * 100); string valstr = string. valueof (midval); // convert it to string rail = valstr. substring (valstr. length ()-2); // take the decimal part long preint = (midval/100); string prefix = convert (preint); string suffix = ""; // process the number of decimal places if (rail. equals ("00") {suffix = "whole";} else {suffix = data [rail. charat (0)-'0'] + "" + data [rail. charat (1)-'0'] + "points";} return prefix + suffix; // return the correct representation} public static void main (string [] ARGs) {system. out. println (convert (2000000007); system. out. println (convert (2000000007.211 ));}}

 

Pen: amount conversion, the amount of Arabic numerals is converted into a traditional Chinese form, such as: (¥1011)-> (one thousand and one pick up one yuan) Output

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.