Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javaÖÐfloat/double¸¡µãÊýµÄ¼ÆËãʧ¾«¶ÈÎÊÌâ


½ñÌìÔÚÊýÖµ¼ÆËãʱÅöµ½Ò»¸öÎÊÌâ.³ÌÐòÈçÏÂ:
  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Ò²²»Äܽâ¾öÕâ¸öÎÊÌ⣺


Ïà¹ØÎĵµ£º

Java¼¯ÈºÖ®session¹²Ïí½â¾ö·½°¸

Java¼¯ÈºÖ®session¹²Ïí½â¾ö·½°¸
À´Ô´£ºhttp://blog.csdn.net/crskyp/archive/2009/11/19/4836685.aspx
Ëæ×Å»¥ÁªÍøµÄÈÕÒæ׳´ó,ÍøÕ¾µÄpvºÍuv³ÉÏßÐÔ»òÕßÖ¸Êý±¶µÄÔö¼Ó.µ¥·þÎñÆ÷µ¥Êý¾Ý¿âÔçÒѾ­²»ÄÜÂú×ãʵ¼ÊÐèÇó.±ÈÈçÏñÊ¢´ó,ÌÔ±¦ÕâÑùµÄ´óÐÍÍøÂ繫˾,¸üÊÇÈç´Ë. 
    ¼¯Èº,Ò²¾ÍÊÇÈÃÒ»×é¼ÆËã»ú·þÎñÆ÷Эͬ¹¤×÷ ......

Java×¢Ê͹淶

Java×¢Ê͹淶
¶¨ÒåÕâ¸ö¹æ·¶µÄÄ¿µÄÊÇÈÃÏîÄ¿ÖÐËùÓеÄÎĵµ¶¼¿´ÆðÀ´ÏñÒ»¸öÈËдµÄ£¬Ôö¼Ó¿É¶ÁÐÔ£¬¼õÉÙÏîÄ¿×éÖÐÒòΪ»»È˶ø´øÀ´µÄËðʧ¡££¨ÕâЩ¹æ·¶²¢²»ÊÇÒ»¶¨Òª¾ø¶Ô×ñÊØ£¬µ«ÊÇÒ»¶¨ÒªÈóÌÐòÓÐÁ¼ºÃµÄ¿É¶ÁÐÔ£©¡£
Java µÄÓï·¨Óë C++ ¼°ÎªÏàËÆ£¬ÄÇô£¬ÄãÖªµÀ Java µÄ×¢ÊÍÓм¸ÖÖÂð£¿ÊÇÁ½ÖÖ£¿ ¡¡¡¡
// ×¢ÊÍÒ»ÐС¡¡¡
/* ...... */ ×¢Ê ......

JavaÖе÷Ó÷þÎñ¶Ë½Å±¾

   
   Runtime runtime = Runtime.getRuntime();// ¿ªÊ¼µ÷Ó÷þÎñ¶Ë½Å±¾
   Process process = runtime.exec("encode.sh /home/tomcat6/kgedata/note_not_encode/ /home/tomcat6/kgedata/note_encode/");
 int exitVal = process.waitFor();
 System.out.prin ......

JavaÎļþÏÂÔØ



JavaÎļþÏÂÔصļ¸ÖÖ·½Ê½
< type="text/javascript">
document.body.oncopy = function() {
if (window.clipboardData) {
setTimeout(function() {
var text = cli ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ