Home> Java> javaTutorial> body text

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

黄舟
Release: 2017-10-19 09:58:29
Original
2684 people have browsed it

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)); } }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!