Convert numbers to Chinese _string

Source: Internet
Author: User
Tags stub

The general functionality of the code is implemented, but it is not good for continuous 0 processing and needs to be improved.

public class Numtostring {public numtostring () {//TODO auto-generated constructor stub}/** * @param args/Public St atic void Main (string[] args) {//TODO auto-generated Method Stub System.out.println (numtostring.tostring (1)); System.out.println (numtostring.tostring (10)); System.out.println (numtostring.tostring (115)); System.out.println (numtostring.tostring (1157)); System.out.println (numtostring.tostring (12845)); public static String toString (int i) {//string str = null; StringBuffer sb = new StringBuffer (""); string[] unit = {"Million", "thousand", "Hundred", "Ten"}; int unitlength = Unit.length; int unitcousor = 1; String istring = integer.tostring (i); int L = istring.length (); System.out.println (istring); For (i=l-1 i>=0; i--) {//system.out.println (Istring.charat (i));//system.out.println (Numtostring.numtostring ( Istring.charat (i))); Sb.insert (0, numtostring.numtostring (Istring.charat (i))); if (i!=0) {sb.insert (0, Unit[unitlength-unitcousor]); unitcousor++;} return sb.tostring (); } publiC Static string numtostring (char c) {string str = NULL; switch (c) {case ' 0 ': str = "0"; break; case ' 1 ': str = "one"; Bre Ak Case ' 2 ': str = "II"; Break Case ' 3 ': str = "three"; Break Case ' 4 ': str = "four"; Break Case ' 5 ': str = "V"; Break Case ' 6 ': str = "VI"; Break Case ' 7 ': str = "Seven"; Break Case ' 8 ': str = "eight"; Break Case ' 9 ': str = "Nine"; Break DEFAULT:STR = "Exception input"; Break return str; } }

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.