Liang Yong (danniel Liang) Java Textbook example: Java program purchase amount according to the tax rate for sales tax Java value reserved 2 decimal places method

Source: Internet
Author: User

Package com.swift;

Import Java.util.Scanner;

public class Purchasetaxdecimalstwo {

public static void Main (string[] args) {


Scanner scan=new Scanner (system.in);//Scan Workbench Input
Double purchaseamount=scan.nextdouble ();//Enter a value to assign the purchase amount variable
System.out.println (Purchaseamount);
Double taxrate=0.06;//tax Rate
Double tax;
tax=purchaseamount*taxrate;//Tax Multiple decimal places
SYSTEM.OUT.PRINTLN (tax);
SYSTEM.OUT.PRINTLN ((int) (tax*100));//multiply by 100 except 100.0 reserve 2 decimal places
SYSTEM.OUT.PRINTLN ((int) (TAX*100)/100.0);//cannot divide 100
}

}

Liang Yong (danniel Liang) Java Textbook example: Java program purchase amount according to the tax rate for sales tax Java value reserved 2 decimal places method

Related Article

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.