How to Round Decimals to 2 Places after the Decimal Point (Java)

后端 未结 4 467
挽巷
挽巷 2021-01-16 10:48

I am fairly new to java and I have to create this program to which I have no idea where to start. Can someone please help me with what to do and how to write the code to get

4条回答
  •  执笔经年
    2021-01-16 11:41

    You could simply try this one

    DecimalFormat df=new DecimalFormat("#.##");

    For Tax

    double totalwotax = 0.8130000000000001;
    System.out.println("The tax for the subtotal is $" + df.format(totalwotax));

    Output: 0.81

    For Total

    double totalandtax = 14.363000000000001;
    System.out.println("The total for your bill with tax is $" + df.format(totalandtax));

    Output: 14.36

提交回复
热议问题