BigDecimal处理数字 “加减”

BigDecimal a = new BigDecimal("99.215").setScale(2, 
						BigDecimal.ROUND_HALF_UP); 
						System.out.println(a); 

						BigDecimal b = new BigDecimal("99.115").setScale(2, 
						BigDecimal.ROUND_HALF_UP); 
						System.out.println(b); 

						BigDecimal c = new BigDecimal("99.215").setScale(2, 
						BigDecimal.ROUND_HALF_UP); 
						System.out.println(c);

BigDecimal a=new BigDecimal(
						new String("1234532458945.568"));  

				BigDecimal b=new BigDecimal(new String("12345324.56"));  

				String c=a.add(b).toString();//加  

				String d=a.subtract(b).toString();//减  

				String e=a.multiply(b).toString();//乘  

				String f=a.divide(b).toString();//除  

				System.out.println(c);  

				System.out.println(d);  

				System.out.println(e);  

				System.out.println(f);  

BigDecimal bigTotal = new BigDecimal(0d);
BigDecimal fre = new BigDecimal(
									String.valueOf(cusbills.getFreight())).
									setScale(2, BigDecimal.ROUND_HALF_UP);
							
							BigDecimal dis = new BigDecimal(
									String.valueOf(cusbills.getDispatch())).
									setScale(2, BigDecimal.ROUND_HALF_UP);
							
							BigDecimal ins = new BigDecimal(
									String.valueOf(cusbills.getInsurance())).
									setScale(2, BigDecimal.ROUND_HALF_UP);
							
							BigDecimal tra = new BigDecimal(
									String.valueOf(cusbills.getTransfer())).
									setScale(2, BigDecimal.ROUND_HALF_UP);
							
							BigDecimal oth = new BigDecimal(
									String.valueOf(cusbills.getOther())).
									setScale(2, BigDecimal.ROUND_HALF_UP);
							
							bigTotal = bigTotal.add(fre.add(dis.add(ins.add(tra.add(oth)))));

你可能感兴趣的:(C++,c,C#,F#,UP)