javaÖÐfloat/double¸¡µãÊýµÄ¼ÆËãʧ¾«¶ÈÎÊÌâ
javaÖи¡µãÊýµÄ¼ÆËã
½ñÌìÔÚÊýÖµ¼ÆËãʱÅöµ½Ò»¸öÎÊÌâ.³ÌÐòÈçÏÂ:
double a = (3.3-2.4)/0.1;
System.out.println(a);
Äã¿ÉÄÜÈÏΪ½á¹ûºÜ¼òµ¥,²»¾ÍÊÇ9Âï,ÊÇÊÂʵÉÏ,½á¹ûΪ:8.999999998,ΪʲôÄØ?ÎÒ·ÔÄÁËһЩ×ÊÁÏ,ÖÕÓÚÕÒ³öÁËÔÒò.
Ϊʲô¸¡µãÊý»á¶ªÊ§¾«¶È£¿
Ê®½øÖÆÊýµÄ¶þ½øÖƱíʾ¿ÉÄܲ»¹»¾«È·
¸¡µãÊý»òÊÇË«¾«¶È¸¡µãÊýÎÞ·¨¾«È·±íʾµÄÇé¿ö²¢²»ÉÙ¼û¡£¸¡µãÊýֵû°ì·¨ÓÃÊ®½øÖÆÀ´¾«È·±íʾµÄÔÒòÒª¹é¾ÌÓÚCPU±íʾ¸¡µãÊýµÄ·½·¨¡£ÕâÑùµÄ»°Äú¾Í¿ÉÄÜ»áÎþÉüһЩ¾«¶È£¬ÓÐЩ¸¡µãÊýÔËËãÒ²»áÒýÈëÎó²î¡£ÒÔÉÏÃæÌáµ½µÄÇé¿öΪÀý£¬2.4µÄ¶þ½øÖƱíʾ²¢·Ç¾ÍÊǾ«È·µÄ2.4¡£·´¶ø×îΪ½Ó½üµÄ¶þ½øÖƱíʾÊÇ 2.3999999999999999¡£ÔÒòÔÚÓÚ¸¡µãÊýÓÉÁ½²¿·Ö×é³É£ºÖ¸ÊýºÍβÊý¡£¸¡µãÊýµÄֵʵ¼ÊÉÏÊÇÓÉÒ»¸öÌض¨µÄÊýѧ¹«Ê½¼ÆËãµÃµ½µÄ¡£ÄúËùÓöµ½µÄ¾«¶ÈËðʧ»áÔÚÈκβÙ×÷ϵͳºÍ±à³Ì»·¾³ÖÐÓöµ½¡£
×¢Ò⣺ Äú¿ÉÒÔʹÓÃBinary Coded Decimal (BCD)¿âÀ´±£³Ö¾«¶È¡£BCDÊý×Ö±àÂë·½·¨»á°Ñÿһ¸öÊ®½øÖÆÊý×Öλµ¥¶À±àÂë¡£
ÀàÐÍʧÅä
Äú¿ÉÄÜ»ìºÏÁ˸¡µãÊýºÍË«¾«¶È¸¡µãÊýÀàÐÍ¡£ÇëÈ·¶¨ÄúÔÚ½øÐÐÊýѧÔËËãµÄʱºòËùÓеÄÊý¾ÝÀàÐÍÈ«²¿Ïàͬ¡£
×¢Ò⣺floatÀàÐ͵ıäÁ¿Ö»ÓÐ7λµÄ¾«¶È£¬¶ødoubleÀàÐ͵ıäÁ¿ÓÐ15λµÄ¾«¶È¡£
ÈçºÎ½øÐи¡µãÊý¾«¶È¼ÆË㣿
JavaÖеļòµ¥¸¡µãÊýÀàÐÍfloatºÍdouble²»Äܹ»½øÐÐÔËËã¡£²»¹âÊÇJava£¬ÔÚÆäËüºÜ¶à±à³ÌÓïÑÔÖÐÒ²ÓÐÕâÑùµÄÎÊÌâ¡£ÔÚ´ó¶àÊýÇé¿öÏ£¬¼ÆËãµÄ½á¹ûÊÇ׼ȷµÄ£¬µ«ÊǶàÊÔ¼¸´Î£¨¿ÉÒÔ×öÒ»¸öÑ»·£©¾Í¿ÉÒÔÊÔ³öÀàËÆÉÏÃæµÄ´íÎó¡£ÏÖÔÚÖÕÓÚÀí½âΪʲôҪÓÐBCDÂëÁË¡£
Õâ¸öÎÊÌâÏ൱ÑÏÖØ£¬Èç¹ûÄãÓÐ9.999999999999Ôª£¬ÄãµÄ¼ÆËã»úÊDz»»áÈÏΪÄã¿ÉÒÔ¹ºÂò10ÔªµÄÉÌÆ·µÄ¡£
ÔÚÓеıà³ÌÓïÑÔÖÐÌṩÁËרÃŵĻõ±ÒÀàÐÍÀ´´¦ÀíÕâÖÖÇé¿ö£¬µ«ÊÇJavaûÓС£ÏÖÔÚÈÃÎÒÃÇ¿´¿´ÈçºÎ½â¾öÕâ¸öÎÊÌâ¡£
ËÄÉáÎåÈë
ÎÒÃǵĵÚÒ»¸ö·´Ó¦ÊÇ×öËÄÉáÎåÈë¡£MathÀàÖеÄround·½·¨²»ÄÜÉèÖñ£Áô¼¸Î»Ð¡Êý£¬ÎÒÃÇÖ»ÄÜÏóÕâÑù£¨±£ÁôÁ½Î»£©£º
public double round(double value){
return Math.round(value*100)/100.0;
}
·Ç³£²»ÐÒ£¬ÉÏÃæµÄ´úÂë²¢²»ÄÜÕý³£¹¤×÷£¬¸øÕâ¸ö·½·¨´«Èë4.015Ëü½«·µ»Ø4.01¶ø²»ÊÇ4.02£¬ÈçÎÒÃÇÔÚÉÏÃæ¿´µ½µÄ
4.015*100=401.49999999999994
Òò´ËÈç¹ûÎÒÃÇÒª×öµ½¾«È·µÄËÄÉáÎåÈ룬²»ÄÜÀûÓüòµ¥ÀàÐÍ×öÈκÎÔËËã
java.text.DecimalFormatÒ²²»Äܽâ¾öÕâ¸öÎÊÌâ
Ïà¹ØÎĵµ£º
¹Ø¼ü×Ö: filter
¹ýÂËÆ÷FilterÒ²¾ßÓÐÉúÃüÖÜÆÚ£ºinit()->doFilter()->destroy()£¬Óɲ¿ÊðÎļþÖеÄfilterÔªËØÇý¶¯¡£ÔÚservlet2.4ÖУ¬¹ýÂËÆ÷ͬÑù¿ÉÒÔÓÃÓÚÇëÇó·ÖÅÉÆ÷£¬µ«ÐëÔÚweb.xmlÖÐÉùÃ÷£¬<dispatcher>INCLUDE»òFORWARD»òREQUEST»òERROR</dispatcher>¸ÃÔªËØλÓÚfilter-mappingÖС£
Ò»¡ ......
//¼òµ¥µÄjavaÈÕÆÚ¸ñʽ¿ØÖÆ
java.Text.SimpleDateFormat format = new java.Text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//ÄãÏëÒªµÄ¸ñʽ
//×¢ÒâÔµÄλÖÃÒª´óдµÄMM Òª²»¾Í¿´µ½µÄ²»ÊÇÕýÈ·ÏÔʾ£¬¿ÉÒÔ°ÑÄãÏëҪת»»µÄÈÕÆÚת»»ÎªÏàÓ¦µÄ¸ñʽ°¡
format.format(new java.util.Date());//dateΪÈÕÆÚÐÍÊý¾Ý£¬¿ÉÒÔÈÎÒ ......
Map´æ´¢µÄÊÇkey->valueµÄÖµ¶Ô£¬keyµÄÖµÊÇΨһµÄ£¬¶øvalueµÄÖµ¿ÉÒÔÖظ´¡£Í¨³£Ê¹ÓõÄÊÇHashMap»òTreeMap£¬Èç¹û¿¼ÂÇÐÔÄÜ£¬Ê¹ÓÃHashMap¡£TreeMapʹÓúìºÚÊ÷ʵÏÖ£¬±£ÁôÓÐkeyֵ˳ÐòÐÔ£¬»á×Ô¶¯°´ÕÕkeyÖµÅÅÐò¡£
ĬÈÏÊÇ°´ÕÕkeyÖµµÄÉýÐòÅÅÐò£¬keyÖµ±ØÐëʵÏÖ Comparator½Ó¿Ú¡£Èç¹ûÏ£Íû°´ÕÒÒ»¶¨¹æÔòÅÅÐò£¬ÔòÐèÒªÖØж¨Òåcompareº¯Êý ......
ÎÊÌâÓò:
--ϵͳÖÐÄãÐèÒª»ñµÃij¸öÀàµÄΨһʵÀý£¬ËùÓпͻ§¶Ë¶ÔËüµÄ·ÃÎʶ¼½«Í¨¹ýÒ»¸ö¹«¹²µÄ·ÃÎʵã»ñµÃ
--´´½¨Ò»¸öÀಢʹÆ䣺(A)¶¨ÒåÒ»¸ö˽ÓеĹ¹ÔìÆ÷£¨B£©¶¨ÒåÒ»¸ö˽ÓС¢¾²Ì¬µÄ±äÁ¿Ö¸Ïò×Ô¼º£¨C£©¶¨ÒåÒ»¸ö¹«ÓС¢¾²Ì¬µÄ·ÃÎÊ·½·¨ÓÃÓÚ·µ»Ø¸ÃÀàµÄÒ»¸öΨһʵÀý
·ÖΪ ¶öººÊ½ ºÍ ÀÁººÊ½,ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄʾÀý´úÂ룬Ӧ¸Ã ......
javaÖÐʹÓöþά Êý×é
ognNf_v
public class Array2D...{
m@EvM)y0e2r
s
public static void main(String[] args)...{JAVAÖÐÎÄÕ¾ÉçÇøÃÅ»§ ~j!lSR^ z5bR5O
int myInt[][]=new int[5][10];
@XH3ao\
  ......