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

后端 未结 4 491
挽巷
挽巷 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:22

    You can use the format() method instead of println():

    System.out.format("The subtotal is $%.2f%n",  total);  
    

    A description of the format syntax can be found here.

提交回复
热议问题