ÔÚJavaÖÐʵÏÖ¸¡µãÊýµÄ¾«È·¼ÆËã
±êÌâ ÔÚJavaÖÐʵÏÖ¸¡µãÊýµÄ¾«È·¼ÆËã AYellow£¨Ô×÷£© ÐÞ¸Ä
¹Ø¼ü×Ö Java ¸¡µãÊý ¾«È·¼ÆËã
ÎÊÌâµÄÌá³ö£º
Èç¹ûÎÒÃDZàÒëÔËÐÐÏÂÃæÕâ¸ö³ÌÐò»á¿´µ½Ê²Ã´£¿
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){
return Math.round(value*100)/100.0;
}
·Ç³£²»ÐÒ£¬ÉÏÃæµÄ´úÂë²¢²»ÄÜÕý³£¹¤×÷£¬¸øÕâ¸ö·½·¨´«Èë4.015Ëü½«·µ»Ø4.01¶ø²»ÊÇ4.02£¬ÈçÎÒÃÇÔÚÉÏÃæ¿´µ½µÄ
4.015*100=401.49999999999994
Òò´ËÈç¹ûÎÒÃÇÒª×öµ½¾«È·µÄËÄÉáÎåÈ룬²»ÄÜÀûÓüòµ¥ÀàÐÍ×öÈκÎÔËËã
java.text.DecimalFormatÒ²²»Äܽâ¾öÕâ¸öÎÊÌ⣺
System.out.println(new java.text.DecimalFormat("0.00").format(4.025));
Êä³öÊÇ4.02
BigDecimal
ÔÚ¡¶Effective Java¡·Õâ±¾ÊéÖÐÒ²Ìáµ½Õâ¸öÔÔò£¬floatºÍdoubleÖ»ÄÜÓÃÀ´×ö¿Æѧ¼ÆËã»òÕßÊǹ¤³Ì¼ÆË㣬ÔÚÉÌÒµ¼ÆËãÖÐÎÒÃÇÒªÓÃjava.math.BigDecimal¡£BigDecimalÒ»¹²ÓÐ4¸ö¹»Ôì·½·¨£¬ÎÒÃDz»¹ØÐÄÓÃBigIntegerÀ´¹»ÔìµÄÄÇÁ½¸ö£¬ÄÇô»¹ÓÐÁ½¸ö£¬ËüÃÇÊÇ£º
BigDecimal(double val)
 
Ïà¹ØÎĵµ£º
1. Ê×ÏÈString²»ÊôÓÚ8ÖÖ»ù±¾Êý¾ÝÀàÐÍ£¬StringÊÇÒ»¸ö¶ÔÏó¡£
ÒòΪ¶ÔÏóµÄĬÈÏÖµÊÇnull£¬ËùÒÔStringµÄĬÈÏÖµÒ²ÊÇnull£»µ«ËüÓÖÊÇÒ»ÖÖÌØÊâµÄ¶ÔÏó£¬ÓÐÆäËü¶ÔÏóûÓеÄһЩÌØÐÔ¡£
2. new String()ºÍnew String(“”)¶¼ÊÇÉêÃ÷Ò»¸öеĿÕ×Ö·û´®£¬ÊÇ¿Õ´®²»ÊÇnull£»
3. String str=”kvill”£»
String str=n ......
½ñÌìÔÙÂÛ̳¿´µ½ÁËÓÐÈËÎÊJAVAÃüÃû¹æ·¶£¬ÎÒ¾õµÃÕâ¸öÎÊÌâµÄÈ·ÐèҪעÖØÒ»ÏÂ
ÒòΪ¶ÔÓÚÒ»¸ö³ÌÐòÀ´Ëµ ³ÌÐòµÄ¸ñʽÊǷdz£ÖØÒª£¬Ãû×ÖÆð³ÉʲôÑù¿ÉÒÔ¿´³öÕâ¸öÈ˵ıà³ÌÄÜÁ¦£¬
Èç¹ûÒ»¸öÈ˵ijÌÐòдµÄ·Ç³£µÄÂÒ£¬Ãû×Öûһµã¹æ·¶µÄ»°»á¾õµÃ³ÌÐòºÜ"³ó"£¬Õâ»áÈöÁÕ߸ù±¾Ã»
ÐÄ˼ÍùÏ¿´
ÏÂÃæÕª×ÔÂÛ̳һÍøÓѶÔÃüÃû¹æ·¶µÄ×ܽ᣺
1.°ü
ÓÉСР......
Java ÖÐÀàºÍ·½·¨ÐÞÊηû
ÀàµÄÐÞÊÎ
·ÃÎÊÐÞÊηû ÐÞÊηû class ÀàÃû extends ¸¸ÀàÃû³Æ implements ½Ó¿ÚÃû³Æ£¨notes: ·ÃÎÊÐÞÊηû·ûÓëÐÞÊηûµÄλÖÿÉÒÔ»¥»»£©
·ÃÎÊÐÞÊηû
Ãû³Æ
˵Ã÷
±¸×¢
pubic
¿ÉÒÔ±»ËùÓÐÀà·ÃÎÊ(ʹÓÃ)
public Àà±ØÐ붨ÒåÔÚºÍÀàÃûÏàͬµÄͬÃûÎļþÖÐ
package
¿ÉÒÔ±»Í¬Ò»¸ö°üÖеÄÀà·ÃÎÊ(ʹÓÃ)
ĬÈϵķÃÎ ......
//»ñÈ¡Êý¾Ý¿âÊý¾Ý·µ»Ølist
public List queryAll(int fcateId) {
List list = new ArrayList();
String sql = "select * from g_Account where fCateID=? order by fCode";
Connection con = SqlHelp.getConn();//»ñµÃÁ¬½Ó£¬sqlhelp×Ô¼ºÐ´µÄ¹¤¾ßÀà
PreparedStatement pst = null;
ResultSet rs = null;
......