小编Vis*_*oon的帖子

如何将百分比变量格式化为2位小数?

该程序基本上使用文本文件,读取数据和执行功能:

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

    mark= s.nextDouble();

    double percent= (mark / tm )*100  ;

    System.out.println("Student Name      : " +name );

    System.out.println("Percentage In Exam: " +percent+"%"); 

    System.out.println(" ");
}
Run Code Online (Sandbox Code Playgroud)

我想将百分比值格式化为2位小数,但因为它在while循环中,所以我不能使用printf.

java decimal number-formatting

13
推荐指数
3
解决办法
2万
查看次数

标签 统计

decimal ×1

java ×1

number-formatting ×1