1 7 8 18 package java.math; 19 20 83 public enum RoundingMode { 84 85 107 UP(BigDecimal.ROUND_UP), 108 109 130 DOWN(BigDecimal.ROUND_DOWN), 131 132 154 CEILING(BigDecimal.ROUND_CEILING), 155 156 178 FLOOR(BigDecimal.ROUND_FLOOR), 179 180 204 HALF_UP(BigDecimal.ROUND_HALF_UP), 205 206 229 HALF_DOWN(BigDecimal.ROUND_HALF_DOWN), 230 231 261 HALF_EVEN(BigDecimal.ROUND_HALF_EVEN), 262 263 284 UNNECESSARY(BigDecimal.ROUND_UNNECESSARY); 285 286 final int oldMode; 288 289 295 private RoundingMode(int oldMode) { 296 this.oldMode = oldMode; 297 } 298 299 307 public static RoundingMode valueOf(int rm) { 308 switch(rm) { 309 310 case BigDecimal.ROUND_UP: 311 return UP; 312 313 case BigDecimal.ROUND_DOWN: 314 return DOWN; 315 316 case BigDecimal.ROUND_CEILING: 317 return CEILING; 318 319 case BigDecimal.ROUND_FLOOR: 320 return FLOOR; 321 322 case BigDecimal.ROUND_HALF_UP: 323 return HALF_UP; 324 325 case BigDecimal.ROUND_HALF_DOWN: 326 return HALF_DOWN; 327 328 case BigDecimal.ROUND_HALF_EVEN: 329 return HALF_EVEN; 330 331 case BigDecimal.ROUND_UNNECESSARY: 332 return UNNECESSARY; 333 334 default: 335 throw new IllegalArgumentException ("argument out of range"); 336 } 337 } 338 } 339 | Popular Tags |