¡¾×ª¡¿Java double Ïà¼ÓµÄ¹ÖÊÂÇé
(±¾ÎÄתÔØ×Ô£ºhttp://hi.baidu.com/edilyxin/blog/item/27dc152aba3e10315343c19c.html)
ÎÊÌâµÄÌá³ö£º
±àÒëÔËÐÐÏÂÃæÕâ¸ö³ÌÐò»á¿´µ½Ê²Ã´£¿
public class Test{
public static void main(String args[]){
System.out.println(0.05+0.01);
System.out.println(1.0-0.42);
System.out.println(4.015*100);
System.out.println(123.3/100);
}
};
ÄãûÓп´´í£¡½á¹ûȷʵÊÇ
0.060000000000000005
0.5800000000000001
401.49999999999994
1.2329999999999999
JavaÖеļòµ¥¸¡µãÊýÀàÐÍfloatºÍdouble²»Äܹ»½øÐÐÔËËã¡£²»¹âÊÇJava£¬ÔÚÆäËüºÜ¶à±à³ÌÓïÑÔÖÐÒ²ÓÐÕâÑùµÄÎÊÌâ¡£ÔÚ´ó¶àÊýÇé¿öÏ£¬¼ÆËãµÄ½á¹ûÊÇ׼ȷµÄ£¬µ«ÊǶàÊÔ¼¸´Î£¨¿ÉÒÔ×öÒ»¸öÑ»·£©¾Í¿ÉÒÔÊÔ³öÀàËÆÉÏÃæµÄ´íÎó¡£ÏÖÔÚÖÕÓÚÀí½âΪʲôҪÓÐBCDÂëÁË¡£
Õâ¸öÎÊÌâÏ൱ÑÏÖØ£¬Èç¹ûÄãÓÐ9.999999999999Ôª£¬ÄãµÄ¼ÆËã»úÊDz»»áÈÏΪÄã¿ÉÒÔ¹ºÂò10ÔªµÄÉÌÆ·µÄ¡£
ÔÚÓеıà³ÌÓïÑÔÖÐÌṩÁËרÃŵĻõ±ÒÀàÐÍÀ´´¦ÀíÕâÖÖÇé¿ö£¬µ«ÊÇJavaûÓС£ÏÖÔÚÈÃÎÒÃÇ¿´¿´ÈçºÎ½â¾öÕâ¸öÎÊÌâ¡£
ËÄÉáÎåÈë
ÎÒÃǵĵÚÒ»¸ö·´Ó¦ÊÇ×öËÄÉáÎåÈë¡£MathÀàÖеÄround·½·¨²»ÄÜÉèÖñ£Áô¼¸Î»Ð¡Êý£¬ÎÒÃÇÖ»ÄÜÏóÕâÑù£¨±£ÁôÁ½Î»£©£º
public double round(double value){&
Ïà¹ØÎĵµ£º
Ò»¡¢Ê¹ä¯ÀÀÆ÷²»»º´æÒ³ÃæµÄ¹ýÂËÆ÷
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* ÓÃÓÚµÄʹ Browser ²» ......
Java°æÖ§¸¶±¦½Ó¿Ú¿ª·¢
ÐèÇ󣺵÷ÓÃÖ§¸¶±¦½Ó¿ÚµÄ½Ó¿Ú²¢¼¯³Éµ½É̳Ç
µ÷ÓÃÖ§¸¶±¦½Ó¿ÚËùÐèÒªµÄ“Ö§¸¶±¦ºÏ×÷»ï°éid”ºÍ“Ö§¸¶±¦°²È«Ð£ÑéÂ딹«Ë¾¶¼¸øÌṩºÃÁË£¬Ö§¸¶±¦¹Ù·½ÄÇÀïÒ²ÓиýӿڵēʵÎïÉÌÆ·½»Ò×·þÎñ¼¯³É¼¼ÊõÎĵµ”¼°Ïà¹ØµÄDEMOÔ´Âë¡£¹«Ë¾ÈÃÎÒÓÃJAVAÀ´Ð´£¬ÖÕÓÚÔÝʱ²»ÓÃÔÙдJSÁË£¬ºÙºÙ&hel ......
¶ÔÓÚ½«ÒªÊ¹ÓõÄJSP¹æ·¶µÄÒ»¸öÌص㣬¾ÍÊÇJSP±í´ïʽÓïÑÔ¡£Ôںܴó³Ì¶ÈÉÏ£¬ËüÊÇÓÐÒâ¼ò»¯µÄ£¬²¢¶ÀÁ¢ÓÚJSP¡£
ÔÚJSPµÄÔçÆÚ°æ±¾ÖУ¬Java´úÂëÒԽű¾µÄÐÎʽǶÈëµ½JSPÒ³ÃæÖУ¬ÀýÈ磺
<%
MyBean bean = new MyBean();
String name = bean.getName();
out.println(name);
%>
Õâ¸ö½Å±¾´úÂëн¨ÁËÒ»¸öÃûΪMyBeanµÄʵÀý£¬»ñµÃË ......