浮点数转换为人民币读法
package test2;
import java.util.Scanner;
public class T6 {
public static void main(String[] args) {
String[] hanArr = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "染", "捌", "玖"};
String[] unitArr = {"", "十", "百", "千", "万", "十万"};
Scanner input = new Scanner(System.in);
double num = input.nextDouble();
int zheng = (int)num;
long xiao = Math.round(((num - zheng) * 100));
String[] str = new String[]{String.valueOf(zheng), String.valueOf(xiao)};
System.out.println("整数部分为:" + str[0] + ",小数部分为:" + str[1]);
String result = "";
for(int i = 0; i < str[0].length(); i++){
String str1 = str[0].substring(i, i + 1);
if(i != 0){
String leftNum = str[0].substring(i-1, i);
if(!leftNum.equals("0") && !str1.equals("0")){
result += (hanArr[Integer.valueOf(str1)] + unitArr[str[0].length() - i - 1]);
}else if(!leftNum.equals("0") && str1.equals("0")){
result += "零";
}else if(leftNum.equals("0") && !str1.equals("0")){
result += (hanArr[Integer.valueOf(str1)] + unitArr[str[0].length() - i - 1]);
}
}else{
result += (hanArr[Integer.valueOf(str1)] + unitArr[str[0].length() - i - 1]);
}
}
String result2 = "";
for(int i = 0; i < str[1].length(); i++){
String str2 = str[1].substring(i, i + 1);
if(i == 0 && !str2.equals("0")){
result2 += (hanArr[Integer.valueOf(str2)] + "角");
}else if(i == 1 && !str2.equals("0")){
result2 += (hanArr[Integer.valueOf(str2)] + "分");
}
}
System.out.println("最后转换的结果为:" + result + "点" + result2);
}
}