梁勇(Danniel Liang) java教材例题:java程序购买额按税率求营业税 java中数值保留2位小数的方法
package com.swift;
import java.util.Scanner;
public class PurchaseTaxDecimalsTwo {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);//扫描工作台输入
double purchaseAmount=scan.nextDouble();//输入数值赋值 购买额变量
System.out.println(purchaseAmount);
double taxRate=0.06;//税率
double tax;
tax=purchaseAmount*taxRate;//税 多位小数
System.out.println(tax);
System.out.println((int)(tax*100));//乘100除100.0保留2位小数
System.out.println((int)(tax*100)/100.0);//不能除100
}
}
Never waste time any more, Never old man be a yong man