How do I format my percent variable to 2 decimal places?

后端 未结 6 1166
你的背包
你的背包 2021-02-05 09:51

This program is basically working with text files, reading the data & performing functions:

while(s.hasNext()){
    name= s.next();

    mark= s.nextDouble()         


        
6条回答
  •  醉梦人生
    2021-02-05 10:23

    You can do it using String.format

    System.out.println(String.format("%s%.2f%s","Percentage In Exam: " ,percent,"%"));
    

提交回复
热议问题