求一个数数的个位数,十位数,百位数及千位:
int num = 53;
int g = (num / 1) % 10; //个位
int s = (num / 10) % 10; //十位
int b = (num / 100) % 10; //百位
int b = (num / 1000) % 10; //千位
1 amount = String.valueOf(this.dealAmountByXXQ(new BigDecimal(amount), new BigDecimal(100), new BigDecimal(900),5)); 2 3 /** 4 * 如果是整百金额就减paramSub 5 * @param amount 6 * @param start 7 * @param end 8 * @return 9 */ 10 public static BigDecimal dealAmountByXXQ(BigDecimal amount, BigDecimal start, BigDecimal end,Integer paramSub) { 11 if (amount.compareTo(start) == -1) { 12 return amount; 13 } 14 if (amount.compareTo(end) == 1) { 15 return amount; 16 } 17 int amt = amount.intValue(); 18 int sw = (amt / 10) % 10; 19 int gw = (amt / 1) % 10; 20 if (gw == 0 && sw == 0) { 21 amt -=paramSub; 22 } 23 return new BigDecimal(amt); 24 }
// 判断是否整百或整百倍数: int a = 200; if(a%100 == 0) System.out.println("整百、整百的倍数");