1 33 package net.sf.jga.fn.arithmetic; 34 35 import java.math.BigDecimal ; 36 37 44 45 class DecimalMath implements Arithmetic<BigDecimal > { 46 47 static final long serialVersionUID = 2565703485705053014L; 48 49 static private final BigDecimal ZERO = new BigDecimal (0.0); 50 static private final BigDecimal ONE = new BigDecimal (1.0); 51 52 56 57 public BigDecimal valueOf(Number value) throws IllegalArgumentException { 58 if (value instanceof BigDecimal ) 59 return (BigDecimal ) value; 60 else 61 return new BigDecimal (value.toString()); 62 } 63 64 67 68 public BigDecimal zero() { 69 return ZERO; 70 } 71 72 75 76 public BigDecimal one() { 77 return ONE; 78 } 79 80 84 85 public BigDecimal plus (BigDecimal x, BigDecimal y) { 86 return x.add(y); 87 } 88 89 93 94 public BigDecimal minus (BigDecimal x, BigDecimal y) { 95 return x.subtract(y); 96 } 97 98 102 103 104 public BigDecimal multiplies (BigDecimal x, BigDecimal y){ 105 return x.multiply(y); 106 } 107 108 109 113 114 public BigDecimal divides (BigDecimal x, BigDecimal y) { 115 return x.divide(y,BigDecimal.ROUND_HALF_UP); 116 } 117 118 122 123 public BigDecimal negate (BigDecimal x) { 124 return x.negate(); 125 } 126 } 127 | Popular Tags |