Source Code Cross Referenced for BigDecimals.java in  » Ajax » zk » org » zkoss » math » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » zk » org.zkoss.math 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* BigDecimals.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Thu Apr 17 10:25:07     2003, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2002 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:        package org.zkoss.math;
020:
021:        import java.math.BigDecimal;
022:        import java.math.BigInteger;
023:        import java.util.Locale;
024:
025:        import org.zkoss.lang.Objects;
026:        import org.zkoss.math.BigIntegers;
027:
028:        /**
029:         * Utilities and constants of big decimals.
030:         *
031:         * @author tomyeh
032:         */
033:        public class BigDecimals {
034:            /** Represents 0 in big decimal.
035:             * @see #ONE
036:             * @see #MINUS_ONE
037:             */
038:            public static final BigDecimal ZERO = Objects.ZERO_BIG_DECIMAL;
039:            /** Represents 1 in big decimal.
040:             * @see #ZERO
041:             * @see #MINUS_ONE
042:             */
043:            public static final BigDecimal ONE = new BigDecimal(BigInteger.ONE);
044:            /** Represents -1 in big decimal.
045:             * @see #ZERO
046:             * @see #ONE
047:             */
048:            public static final BigDecimal MINUS_ONE = new BigDecimal(
049:                    BigInteger.ONE.negate());
050:
051:            /** Represents our number precision.
052:             */
053:            public static final int NUMBER_PRECISION = 38;
054:
055:            /** Represents our number scale.
056:             */
057:            public static final int NUMBER_SCALE = 6;
058:
059:            /** Represents our fine number precision.
060:             */
061:            public static final int FINE_NUMBER_PRECISION = 20;
062:            /** Represents our fine number scale.
063:             */
064:            public static final int FINE_NUMBER_SCALE = 8;
065:
066:            /** Converts a double to a big decimal with a scale.
067:             *
068:             * <p>It is strongly deprecated to use new Dicimal(double) since
069:             * the scale is unpredictable and usually surprising.
070:             * Example, BigDecimal(.1) will becomes
071:             * .1000000000000000055511151231257827021181583404541015625.
072:             * On the other hand, BigDecimal("0.1") will be 0.1 correctly.
073:             *
074:             * @param scale the BigDecimal's scale
075:             * @param roundingMode the rounding mode
076:             */
077:            public static final BigDecimal toBigDecimal(double v, int scale,
078:                    int roundingMode) {
079:                return new BigDecimal(v).setScale(scale, roundingMode);
080:            }
081:
082:            /** Converts a double to a big decimal with a scale.
083:             * It uses {@link BigDecimal#ROUND_HALF_UP}.
084:             */
085:            public static final BigDecimal toBigDecimal(double v, int scale) {
086:                return toBigDecimal(v, scale, BigDecimal.ROUND_HALF_UP);
087:            }
088:
089:            /** Converts an integer to a big decimal with a scale.
090:             */
091:            public static final BigDecimal toBigDecimal(int v, int scale) {
092:                return new BigDecimal(BigIntegers.toBigInteger(v), scale);
093:            }
094:
095:            /** Converts an integer to a big decimal with a scale.
096:             */
097:            public static final BigDecimal toBigDecimal(long v, int scale) {
098:                return new BigDecimal(BigIntegers.toBigInteger(v), scale);
099:            }
100:
101:            /** Converts an integer to a big decimal with a scale without.
102:             * losing precision -- zero scale in this case.
103:             */
104:            public static final BigDecimal toBigDecimal(int v) {
105:                return v == 0 ? ZERO : new BigDecimal(BigIntegers
106:                        .toBigInteger(v));
107:            }
108:
109:            /** Converts a long to a big decimal with a scale without.
110:             * losing precision -- zero scale in this case.
111:             */
112:            public static final BigDecimal toBigDecimal(long v) {
113:                return v == 0 ? ZERO : new BigDecimal(BigIntegers
114:                        .toBigInteger(v));
115:            }
116:
117:            /** Converts a short to a big decimal with a scale without.
118:             * losing precision -- zero scale in this case.
119:             */
120:            public static final BigDecimal toBigDecimal(short v) {
121:                return v == 0 ? ZERO : new BigDecimal(BigIntegers
122:                        .toBigInteger(v));
123:            }
124:
125:            /** Converts a byte to a big decimal with a scale without.
126:             * losing precision -- zero scale in this case.
127:             */
128:            public static final BigDecimal toBigDecimal(byte v) {
129:                return v == 0 ? ZERO : new BigDecimal(BigIntegers
130:                        .toBigInteger(v));
131:            }
132:
133:            /** Converts an integer to a big decimal with a scale without.
134:             * losing precision -- zero scale in this case.
135:             */
136:            public static final BigDecimal toBigDecimal(Integer v) {
137:                return toBigDecimal(v.intValue());
138:            }
139:
140:            /** Converts a long to a big decimal with a scale without.
141:             * losing precision -- zero scale in this case.
142:             */
143:            public static final BigDecimal toBigDecimal(Long v) {
144:                return toBigDecimal(v.longValue());
145:            }
146:
147:            /** Converts a short to a big decimal with a scale without.
148:             * losing precision -- zero scale in this case.
149:             */
150:            public static final BigDecimal toBigDecimal(Short v) {
151:                return toBigDecimal(v.shortValue());
152:            }
153:
154:            /** Converts a byte to a big decimal with a scale without.
155:             * losing precision -- zero scale in this case.
156:             */
157:            public static final BigDecimal toBigDecimal(Byte v) {
158:                return toBigDecimal(v.byteValue());
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.