KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > type > DecimalType


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/type/DecimalType.java#4 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2005-2006 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.olap.type;
11
12 import mondrian.olap.Util;
13
14 /**
15  * Subclass of {@link NumericType} which guarantees fixed number of decimal
16  * places. In particular, a decimal with zero scale is an integer.
17  *
18  * @author jhyde
19  * @since May 3, 2005
20  * @version $Id: //open/mondrian/src/main/mondrian/olap/type/DecimalType.java#4 $
21  */

22 public class DecimalType extends NumericType {
23     private final int precision;
24     private final int scale;
25
26     /**
27      * Creates a decimal type with precision and scale.
28      *
29      * <p>Examples:<ul>
30      * <li>123.45 has precision 5, scale 2.
31      * <li>12,345,000 has precision 5, scale -3.
32      * </ul>
33      *
34      * <p>The largest value is 10 ^ (precision - scale). Hence the largest
35      * <code>DECIMAL(5, -3)</code> value is 10 ^ 8.
36      *
37      * @param precision Maximum number of decimal digits which a value of
38      * this type can have.
39      * Must be greater than zero.
40      * Use {@link Integer#MAX_VALUE} if the precision is unbounded.
41      * @param scale Number of digits to the right of the decimal point.
42      */

43     public DecimalType(int precision, int scale) {
44         super();
45         Util.assertPrecondition(precision > 0, "precision > 0");
46         this.precision = precision;
47         this.scale = scale;
48     }
49
50     /**
51      * Returns the maximum number of decimal digits which a value of
52      * this type can have.
53      */

54     public int getPrecision() {
55         return precision;
56     }
57
58     /**
59      * Returns the number of digits to the right of the decimal point.
60      */

61     public int getScale() {
62         return scale;
63     }
64
65     public String JavaDoc toString() {
66         return precision == Integer.MAX_VALUE ?
67             "DECIMAL(" + scale + ")" :
68             "DECIMAL(" + precision + ", " + scale + ")";
69     }
70 }
71
72 // End DecimalType.java
73
Popular Tags