菜鸟求有效数字的问题 比如 double number = 3.1415926 这个说,我想保留4位有效数字,用java怎样实现?求解 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.(double) (Math.round(sd3*10000)/10000.0); 这样为保持4位 (double) (Math.round(sd3*100)/100.0); 这样为保持2位. 2.另一种办法 import java.text.DecimalFormat; DecimalFormat df2 = new DecimalFormat("###.00"); DecimalFormat df2 = new DecimalFormat("###.000"); System.out.println(df2.format(doube_var)); 第一个为2位,第二个为3位. 比较常用的就是1楼所说的第二种方法,使用DecimalFormat 类 还有一种有意思的方法double n=((double)(int)(number*10000))/10000; /*import java.lang.Object; //保留四位有效数字 java.lang.Object是默认引进的包public class A6 { public static void main(String[]args) {double x=3.1415926,y ; System.out.println(x) ; y=(double)(Math.round(x*10000)/10000.0) ; System.out.println(y); }}*/import java.text.DecimalFormat; public class A6{ public static void main(String[]args) { double x=3.1415926 ; DecimalFormat df2 = new DecimalFormat("##.00"); DecimalFormat df3 = new DecimalFormat("###.000"); System.out.println(df2.format(x)) ; System.out.println(df3.format(x)) ; }} 一个小问题 关于使用poi读取doc文件的问题 jdk环境变量的问题 怎样在java里面调用oracle里面的自定义数据类型 把ASCII编码转换成为BCD编码 Graphics中drawString怎么实现输出右对齐?求帮忙! web页面中用到applet,不知在html中用<object>标记还是用<applet>标记,两者有何区别? 请问,JAVA的函数传递参数的时候,能传递引用吗??? 一个奇怪的难题!!! jdbc2.0中记录集已得到,取个数得方法是什么??? 拷贝文件目录的进度条JProgressBar,用什么分割进度比较好? UDP协议与TCP协议
DecimalFormat df2 = new DecimalFormat("###.00"); DecimalFormat df2 = new DecimalFormat("###.000"); System.out.println(df2.format(doube_var)); 第一个为2位,第二个为3位.
double n=((double)(int)(number*10000))/10000;
public static void main(String[]args)
{double x=3.1415926,y ;
System.out.println(x) ;
y=(double)(Math.round(x*10000)/10000.0) ;
System.out.println(y);
}}*/import java.text.DecimalFormat;
public class A6
{ public static void main(String[]args)
{
double x=3.1415926 ;
DecimalFormat df2 = new DecimalFormat("##.00");
DecimalFormat df3 = new DecimalFormat("###.000");
System.out.println(df2.format(x)) ;
System.out.println(df3.format(x)) ;
}}