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
Ïà¹ØÎĵµ£º
annotations : ×¢ÊÍ
ºÃ´¦
1.Îĵµ±àÖÆ
2.±àÒëÆ÷¼ì²é
3.´úÂë·ÖÎö
JSR 175 ÊDZà³ÌÓïÑÔµÄÔªÊý¾Ý¹¤¾ß,Ϊ½«ÔªÊý¾ÝºÏ²¢µ½ºËÐÄjavaÓïÑÔÖÐÌṩÕýʽÀíÓɺÍ˵Ã÷
»ù±¾ÖªÊ¶:
×¢ÊͲÉÓÃ"@"±ê¼ÇÐÎʽ,ºóÃæÊÇ×¢ÊÍÃû³Æ,È»ºóÔÚÐèÒªÊý¾Ýʱ,ͨ¹ýname=value¶ÔÏò×¢ÊÍÌṩÊý¾Ý
×¢Ê͵ÄÈý¸ö»ù±¾ÖÖÀà:
±ê¼Ç×¢ÊÍ ......
System.out.println(2.00 -1.10);//0.8999999999999999
ÉÏÃæµÄ¼ÆËã³öµÄ½á¹û²»ÊÇ0.9£¬¶øÊÇÒ»Á¬´®µÄСÊý¡£ÎÊÌâÔÚÓÚ1.1 Õâ¸öÊý×Ö²»Äܱ»¾«È·±íʾ
Ϊһ¸ödouble£¬Òò´ËËü±»±íʾΪ×î½Ó½üËüµÄdouble Öµ£¬¸Ã³ÌÐò´Ó2 ÖмõÈ¥µÄ¾ÍÊÇÕâ¸öÖµ£¬
µ«Õâ¸ö¼ÆËãµÄ½á¹û²¢²»ÊÇ×î½Ó½ü0.9 µÄdoubleÖµ¡£
Ò»°ãµØ˵£¬ÎÊÌâÔÚÓÚ²¢²»ÊÇËùÓеÄСÊý¶¼¿ÉÒ ......
Graphics2D arg£»
float thick=3.0f;
arg1.setStroke(new BasicStroke(thick, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));
arg1.drawLine(first.x, first.y, next.x, next.y);
arg1.setColor(Color.red);
......
µ¥Ì¬¶¨Òå:
SingletonģʽÖ÷Òª×÷ÓÃÊDZ£Ö¤ÔÚJavaÓ¦ÓóÌÐòÖУ¬Ò»¸öÀàClassÖ»ÓÐÒ»¸öʵÀý´æÔÚ¡£
Singletonģʽ¾ÍΪÎÒÃÇÌṩÁËÕâÑùʵÏֵĿÉÄÜ¡£Ê¹ÓÃSingletonµÄºÃ´¦»¹ÔÚÓÚ¿ÉÒÔ½ÚÊ¡Äڴ棬ÒòΪËüÏÞÖÆÁËʵÀýµÄ¸öÊý£¬ÓÐÀûÓÚJavaÀ¬»ø»ØÊÕ£¨garbage c ......
Èý²½£º
Ò»¡¢×Ô¶¨Òå±êǩʵÏÖÀࣺ myTags.java;
¶þ¡¢×Ô¶¨Òå±êÇ©¿âÎļþ£¨TLD£©: myTags.tld;
Èý¡¢Ò»¸öJSPÒ³Ã棺Ëæ±ãдÁË;
Ê×ÏÈmyTags.java
package com.tags;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
public class myTags extends ......