The conversion of Arabic numerals to Chinese traditional form Java implementation

Source: Internet
Author: User

1.

In financial projects, it is often necessary to convert the amount of Arabic numerals into Chinese traditional forms. The renminbi is kept to a point.

If input: 16700 return: one Wan qi Bai yuan

such as input: 167.5785 return: Bai Lu Qi yuan Wooker points

(May use the Chinese character reference: 0, one, II, three, the restaurant, Wu, Lu, Qi, BA, JIU, pick, Bai, thousand, million, million, trillion, yuan, angle, cent.)

Ideas: A, with two arrays, capnumber[10], respectively, stored 0, one, two, three, the restaurant, Wu, Lu, Qi, BA, JIU.
unit[] 0, round, pick, Bai, Qian, million, billion

Example: 5667234.
5667234/10 Quotient 566,723 + 4 In addition to the number of 1 capnumber[4]+unit[1]= restaurant round
566723/10 Quotient 56,672 + 3 except 2 capnumber[3]+unit[2]= three times
56672/10 Quotient 5,667 + 2 In addition to the number of 3 capnumber[2]+unit[3]= Bai
5667/10 566 + 7 In addition to the number of 4 capnumber[7]+unit[4]=

566/10 Quotient 56 + 6 In addition to the number of 5 capnumber[6]+unit[5]= expect
56/10 5 + 6 In addition to the number of 6 capnumber[6]+unit[6]= land pickup
5/10 Quotient 0 + 5 In addition to the number of 7 capnumber[5]+unit[7]= Wu Bai
The quotient is 0, and the remainder is 0 o'clock, ending

The main use of the StringBuffer Apend method, but the stringbuffer insert (int offset, char c) better solve the problem

public class Renmingbi {private static final char[]  data= {' 0 ', ' one ', ' II ', ' three ', ' the ', ' ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU '};p rivate static Final char[]  units= {' Yuan ', ' pick ', ' bai ', ' thousand ', ' million ', ' pick ', ' bai ', ' thousand ', ' billion ', ' pick ', ' bai ', ' thousand '};p ublic static void Main (string[] args) { SYSTEM.OUT.PRINTLN (CONVERT (1191));} public static String convert (int money) {StringBuffer sb=new stringbuffer (); int Unit=0;while (money!=0) {sb.insert (0, units[unit++]); int Number=money%10;sb.insert (0, Data[number]); money/=10;} return sb.tostring ();} }

The conversion of Arabic numerals to Chinese traditional form Java implementation

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.