Java中的精确处理
让我们看看如何在Java中处理精度-
示例
import java.io.*;
import java.lang.*;
public class Demo{
public static void main(String[] args){
double my_val = 34.909;
System.out.println("The formatted value of 34.909 is ");
System.out.println(String.format("%.7f", my_val));
double my_val_2 = 12.56;
System.out.println("The formatted value of 12.56 is ");
System.out.println(String.format("%.9f", my_val_2));
}
}输出结果
The formatted value of 34.909 is 34.9090000 The formatted value of 12.56 is 12.560000000
名为Demo的类包含主要函数,在该函数中声明了一个双精度整数,并通过指定应格式化的数字对其进行格式化。类似地,定义了另一个double变量,并将其格式化并打印在屏幕上。
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短