Java program --- converts a floating point number into a Renminbi reading method, java reading Method

Source: Internet
Author: User

Java program --- converts a floating point number into a Renminbi reading method, java reading Method

The Code is as follows:

<Span style = "font-size: 18px;"> package test; import java. util. break; // convert the input floating point amount to the public class Num2Rmb {private static double num; private long zheng, xiao; private String [] hanArr = {"0 ", "Yi", "er", "San", "Si", "Wu", "Lu", "Jun "}; private String [] danwei = {"Thousand", "Hundred", "Ten", ""}; private String [] jinwei = {"", "Ten ", ""}; private int [] [] temp = new int [4] [18]; // convert the number of input money to a decimal point and an integer part private void swp () {zheng = (long) num; xiao = Ma Th. round (num-zheng) * 100);} // divide the integer part into three parts by four digits, and add 0 private void divide () {int I, j, k = 0; for (I = 0; I <3; I ++) {long t1 = zheng % 10000; int t = (int) t1; zheng = zheng/10000; for (j = 3; j> = 0; j --) {temp [I] [j] = t % 10; t = t/10 ;}}// checks whether to process the current four bits. private int check (int I) {for (int j = 0; j <4; j ++) if (temp [I] [j]! = 0) return 1; return 0;} // print the result private void print () {// process the integer part first // flag is used to indicate whether the current part needs to process the leading 0int I, j, k, flag = 0, cnt = 0, flag2 = 0; for (I = 2; I> = 0; I --) {if (check (I) = 0) {if (flag = 1 & cnt = 0) {System. out. print ("0"); cnt ++;} flag = 0; continue;} // process leading 0for (j = 0; j <4; j ++) if (temp [I] [j]! = 0) break; flag2 = 1; if (j! = 0 & flag = 1) System. out. print ("zero"); int d; // remove the 0 at the end of the for (d = 3; d> = 0; d --) if (temp [I] [d]! = 0) break; for (k = j; k <= d; k ++) {if (temp [I] [k]! = 0) System. out. print (hanArr [temp [I] [k] + danwei [k]); else if (k-1> = 0 & temp [I] [k-1]! = 0) {System. out. print (hanArr [0]) ;}} flag = 1; System. out. print (jinwei [I]);} if (flag2 = 1) System. out. print ("Yuan"); // process the fractional part if (xiao/10! = 0) System. out. print (hanArr [(int) xiao/10] + ""); if (xiao % 10! = 0) System. out. print (hanArr [(int) xiao % 10] + "points"); System. out. println () ;}// public void run () {swp (); divide (); print () ;}public static void main (String [] args) {pipeline SC = new pipeline (System. in); System. out. println ("Enter the amount of money:"); while (SC. hasNext () {num = SC. nextDouble (); Num2Rmb nr = new Num2Rmb (); // * // debug some nr. swp (); System. out. println (nr. zheng + "" + nr. xiao); nr. divide (); for (int I = 2; I> = 0; I --) {for (int j = 0; j <4; j ++) System. out. print (nr. temp [I] [j]); System. out. println ();} nr. print (); */nr. run (); System. out. println ("Please enter the amount of money:") ;}}</span>



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.