Home  >  Article  >  Java  >  Detailed explanation of the implementation method of converting Java numbers to uppercase

Detailed explanation of the implementation method of converting Java numbers to uppercase

黄舟
黄舟Original
2017-10-19 09:58:292773browse

This article mainly introduces the relevant information on the method of converting numbers to uppercase in Java. I hope this article can help everyone to realize such a function. Friends in need can refer to it

How to convert numbers to uppercase in java

Instructions:

Convert the numerical amount to uppercase, as follows:


public class Test { 
  /** 
   * @param args 
   *      add by zxx ,Nov 29, 2008 
   */ 
  private static final char[] data = new char[] { '零', '壹', '贰', '叁', '肆', 
      '伍', '陆', '柒', '捌', '玖' }; 
 
  private static final char[] units = new char[] { '元', '拾', '佰', '仟', '万', 
      '拾', '佰', '仟', '亿' }; 
 
  public static String convert(int money) { 
    StringBuffer sbf = new StringBuffer(); 
    int unit = 0; 
    while (money != 0) { 
      sbf.insert(0, units[unit++]); 
      int number = money % 10; 
      sbf.insert(0, data[number]); 
      money /= 10; 
    } 
    return sbf.toString(); 
  } 
 
  /** 
   * @param args 
   */ 
  public static void main(String[] args) { 
    // TODO Auto-generated method stub 
    System.out.println(convert(135689123)); 
  } 
}

The above is the detailed content of Detailed explanation of the implementation method of converting Java numbers to uppercase. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn