Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert RMB from lowercase to uppercase by Java

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "how to convert RMB from lowercase to uppercase in Java". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to convert RMB from lowercase to uppercase in Java" can help you solve your doubts.

Public class RMBChange {private static String [] nums = {"zero", "one", "II", "three", "restaurant", "Wu", "Lu", "Qi", "Qing", "nine"} / the unit can also go up private static String [] unit = {"yuan", "pick up", "hundred", "thousand", "ten thousand", "hundred", "thousand", "hundred", "pick up", "hundred", "thousand", "ten thousand"}; / / decimal places can be directly added to this array if there is any need, private static String [] countNum = {"corner", "cent"} Public static String change (String money) {/ / filter empty if (money = = null | | ".equals (money)) {return";} StringBuilder res = new StringBuilder (); String [] splitStr = money.split ("\."); if (splitStr.length > 2) {throw new RuntimeException ("input parameter is not a number!") ;} String front = splitStr [0]; / / display boolean isZero = true; if (front.length () > unit.length) {throw new RuntimeException ("input parameters greater than trillion!") ;} for (int I = 0; I

< front.length(); i++) { // 整数位处理 int dw = front.length() - i - 1; // 用ASCII码获得数字 int index = (front.charAt(i) - '0'); if (index == 0) { isZero = true; if (dw == 0 || dw == 4 || dw == 8) { // 元,万,亿需要拼接 res.append(unit[dw]); } } else { if (isZero && i != 0) { // 多个0只显示一个 res.append(nums[0]); } isZero = false; res.append(nums[index]); res.append(unit[dw]); } } // 判断是否有小数位 if (splitStr.length >

1) {/ / decimal places processing, if not necessary, delete the if and all internal contents isZero = true; String back = splitStr [1]; if (back.length () > countNum.length) {throw new RuntimeException ("decimal places less than [" + countNum [countNum.length-1] + "]!") ;} for (int I = 0; I < back.length (); iTunes +) {int index = (back.charAt (I) -'0'); if (index = = 0) {isZero = true } else {if (isZero & & I! = 0) {res.append (nums [0]);} isZero = false; res.append (nums [index]); res.append (nums [I]) } return res.toString ();}}

test data

Public static void main (String [] args) {System.out.println (change ("9999999999999.99")); / / System.out.println (change ("5020055606500.00")); / / change ("5020055606500.00"); / / five hundred thousand System.out.println (change ("4001500050.16")) / / System.out.println ("7854416"); / System.out.println (change ("9556")); / System.out.println (change ("10086.0")) / / 108lxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx / / one yuan System.out.println (change ("300.00")); / / three hundred yuan System.out.println (change ("2007.01")); / / two thousand seven yuan and one point}

Output result

Jiujiu

Wu Wan 20 billion five hundred thousand five hundred thousand five hundred yuan

Ten hundred and fifty thousand dollars and ten cents

Ten thousand dollars, one hundred and twenty thousand dollars

Nine thousand, five hundred, five dollars.

Ten thousand lxxxxxxxxxxxxxxxx dollars

Two hundred thousand, three hundred, ten thousand, three hundred, three hundred, ten thousand, three thousand, three hundred, ten thousand, three thousand, three hundred, two cents.

Three thousand Lu Bai, one yuan and zero cents.

One yuan

Three hundred yuan

Two thousand seven yuan and one cent

After reading this, the article "how to convert RMB from lowercase to uppercase in Java" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report