double d = 10.00;
System.out.println((d - (int)d)==(double)0.0);
System.out.println((d - (int)d)==(double)0.0);
解决方案 »
- 请问Color.RED和Color.red有什么差别?
- 异常问题,几种情况,谢谢啊。
- 将作为锁的对象释放掉后,以它为锁的线程会如何?释放线程对象的话又如何?
- 为什么会这样!
- 本人是菜鸟.求高手!怎么做个公司的雇员工资支付程序~~~
- 有关Java中System.in.read()输入语句的疑惑!!!!
- 关于布局管理器的问题
- 处理xml文件的问题
- 在线等待,解决后立刻给分!!!!
- 听说windows不在支持java了,那么java的跨平台性怎么体现呢?
- 请问有没有用于JBuilder的浏览器组件?来者有分。
- java.lang.OutOfMemoryError<<no stack trace available>>
不好意思,呵呵
恐怕笨蛋不是他呀
你是高手请指教.
double d = dd.doubleValue();
System.out.println((d - (int)d)==(double)0.0); 笨蛋你不会转换吗!?
integer to String : int i = 42;
String str = Integer.toString(i);
or
String str = "" + i
double to String : String str = Double.toString(i);
long to String : String str = Long.toString(l);
float to String : String str = Float.toString(f);
String to integer : str = "25";
int i = Integer.valueOf(str).intValue();
or
int i = Integer.parseInt(str);
String to double : double d = Double.valueOf(str).doubleValue();
String to long : long l = Long.valueOf(str).longValue();
or
long l = Long.parseLong(str);
String to float : float f = Float.valueOf(str).floatValue();
decimal to binary : int i = 42;
String binstr = Integer.toBinaryString(i);
decimal to hexadecimal : int i = 42;
String hexstr = Integer.toString(i, 16);
or
String hexstr = Integer.toHexString(i);
hexadecimal (String) to integer : int i = Integer.valueOf("B8DA3", 16).intValue();
or
int i = Integer.parseInt("B8DA3", 16);
ASCII code to String int i = 64;
String aChar = new Character((char)i).toString();
integer to ASCII code (byte) char c = 'A';
int i = (int) c; // i will have the value 65 decimal
To extract Ascii codes from a String String test = "ABCD";
for ( int i = 0; i < test.length(); ++i ) {
char c = test.charAt( i );
int i = (int) c;
System.out.println(i);
}
integer to boolean b = (i != 0);
boolean to integer i = (b)?1:0;
note :To catch illegal number conversion, try using the try/catch mechanism. try{
i = Integer.parseInt(aString);
}
catch(NumberFormatException e)
{
}
不过我听说,double型不能用"==",因为它计算所得
的结果一般不等于0,而是0.0000000000几,只能用
"<"或">"来确定,不是真是假,请您再确认以下.
double dd = 0.00;
System.out.println(d==dd);
System.out.println(d==0);Result:
true
true
double dd = 0;
d = 12.49367 - 10.29367;
int decimalPlace = 5;
BigDecimal bd = new BigDecimal(d);
bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);
d = bd.doubleValue();
System.out.println(d);
Double db2 = new Double(dbl.intValue());
if (dbl1.equals(db2))
{
//yes
}
{
//no
}I haven't checked the implementation of Double.equals, but I think it will use Native function to convert doubles to longs (float's binary presentation), then compare two longs.By the way, to cq4550: 路人甲 is not a 笨蛋. He is a great helper.
路人甲 is very very good!
以后再这样说别人,当心打你屁股。
Double d1=new Double(10.00);
Double d2=new Double(10);
从你的需要来看,d1算吗?