JAVA ¾«È·¼ÆËãʱµÄÏÝÚå
troy
ÔÚjava.math°üÖÐÓиöBigDecimalÀ࣬ͨ¹ýÕâ¸öÀà¿ÉÒÔ½øÐо«È·¼ÆËã. ÎÒÃÇÖªµÀBigDecimalÓиösetScale(int ¾«¶È,int ÉáÈëģʽ)·½·¨£¬ËæÖ®¶øÀ´ÎÊÌâ³öÏÖÁË£¬µ±ÔËÐÐÈçÏ´úÂëʱ£º
/**
* @author troy(J2EE)
* @version 1.0
*/
import java.math.*;
public class Test{
public static void main(String[] args){
//¾«¶ÈΪ2,ËÄÉáÎåÈëģʽ
BigDecimal a =new BigDecimal(0.825).setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println(a);
}
}
È´¾ªÆæµØ´òÓ¡³ö½á¹û£º
0.82
Oh My God£¬¶Ô0.825½øÐÐСÊýµãºó±£Áô2λÓÐЧÊý×Ö£¬ËÄÉáÎåÈëºó½á¹ûÓ¦¸ÃÊÇ£º0.83¡£ÎªÊ²Ã´´òÓ¡½á¹ûÊÇ0.82£¿
û´íBigDecimal£¨double val£©Õâ¸ö¹¹ÔìÆ÷ÆÛÆÁËÎÒÃÇ£¬ËüʹÓÃÁË0.825µÄ½üËÆÖµ£¨0.8249999999999……£©À´¹¹ÔìBigDecimal¡£
Ϊʲô»áÕâÑù£¿
ÔÀ´JAVA´æ´¢¸¡µãÊý£¨float¡¢double£©Ê±£¬Ê¹ÓõÄÊÇIEEE754±ê×¼,ÿ¸ö¸¡µãÊýʹÓõÄÊÇ ·ûºÅλ¡¢½×Â롢βÊýÀ´±íʾ£º
````````·ûºÅλ ½×Âë βÊý ³¤¶È
float 1 8 23 32
double 1 11 52 64
ͨ¹ýÕâÖÖ·½·¨±£´æÔÚ¼ÆËã»úÀïÃæµÄ¸¡µãÊý£¬Êµ¼ÊÉÏÊÇËüµÄ½üËÆÖµ¡£¾ÙÀý˵Ã÷ÎÊÌ⣺
¶¨ÒåÒ»¸ödouble 38414.4£¬½«Ëüת»»Îª16½øÖÆ¡£ÎÒÃÇÏȼÆËãÕûÊý²¿·Ö38414µÈÓÚ960E¡£Ð¡Êý´¦Àí£º0.4=0*0.5+0.25*1+0.0625*0+……£¬Êµ¼ÊÉÏÎÒÃÇÓÀÔ¶¼ÆËã²»Íê¡£
½áÂÛ:µ±ÎÒÃǶ¨ÒåÒ»¸ö¸¡µãÊýʱ£¬Çë¸æËß×Ô¼º£¬ÎÒÃǶ¨ÒåÖ»²»¹ýÊÇÕâ¸ö¸¡µãÊýµÄ½üËÆÖµ£¬¼´0.825!=0.825¡£
ΪÁ˱ÜÃâÕâ¸öÎÊÌ⣬ÎÒÃÇÓ¦¸ÃʹÓÃÈçÏ·½·¨£º
/**
* @author troy(J2EE)
* @version 1.0
*/
import java.math.*;
public class Test{
public static void main(String[] args){
BigDecimal a =new BigDecimal("0.825").setScale(2, BigDe
Ïà¹ØÎĵµ£º
Java·´±àÒ빤¾ßEclipse²å¼þ--Jode Decompiler
°²×°·Ç³£µÄ¼òµ¥£º
help => Software Updates => Find and Install... => Search for new features to install£¬
µ¥»÷"New Remote Site..." ÔÚURLÀ¸ÊäÈë http://www.technoetic.com/eclipse/update £¬
È»ºóÏÂÒ»²½£¬¾Í¿ÉÒÔ¿´µ½“j ......
×î½ü¹«Ë¾Òª¿ª·¢Windowsƽ̨ÉϵIJúÆ·£¨ÓÉÓÚÉæ¼°µ½ÉÌÒµ»úÃÜ£¬ËùÒÔÄ¿Ç°ÎÞ·¨¶ÔÕâ¸ö²úÆ·×öÏêϸ½éÉÜ£©£¬²ÉÓÃ.Net¼¼Êõ½øÐпª·¢£¬ÎÒ¸ºÔðµÄÊÇ»ùÓÚ Visual Studio²å¼þ»úÖƵÄÐÐÒµ¿ª·¢¹¤¾ßµÄ¿ª·¢¡£´Ó¿ªÊ¼½Ó´¥.Netµ½ÏÖÔÚÒѾÓнüÈý¸öÔÂÁË£¬¶øÇÒÒ²¿ª·¢³öÁ˵ÚÒ»¸ö°æ±¾£¬¶Ô.NetÒѾÓÐÁËһЩÈÏʶ£¬ÓÉÓÚÒÔÇ°Ö÷ÒªÓÃJava¡¢PythonµÈÓïÑ ......
µ¥Ì¬¶¨Òå:
SingletonģʽÖ÷Òª×÷ÓÃÊDZ£Ö¤ÔÚJavaÓ¦ÓóÌÐòÖУ¬Ò»¸öÀàClassÖ»ÓÐÒ»¸öʵÀý´æÔÚ¡£
Singletonģʽ¾ÍΪÎÒÃÇÌṩÁËÕâÑùʵÏֵĿÉÄÜ¡£Ê¹ÓÃSingletonµÄºÃ´¦»¹ÔÚÓÚ¿ÉÒÔ½ÚÊ¡Äڴ棬ÒòΪËüÏÞÖÆÁËʵÀýµÄ¸öÊý£¬ÓÐÀûÓÚJavaÀ¬»ø»ØÊÕ£¨garbage c ......
ÔʼURL£º http://blog.donews.com/dukejoe/archive/2010/04/28/1575574.aspx
package cn.com.hrbb.samples;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
/**
*
* ÑÝʾʹÓà JACOB : Java COM Bridge ²Ù×Ý Word Îĵµ
*
* ×÷Õߣº¸ßºêΰ(DukeJoe)
......