Package com.storedobject.core
Class DecimalNumber
java.lang.Object
com.storedobject.core.DecimalNumber
- All Implemented Interfaces:
Storable,Comparable<DecimalNumber>
- Direct Known Subclasses:
Rate
Class that represents a decimal number value with a defined number of decimals digits.
This class is immutable.
- Author:
- Syam
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a decimal number of value 0 with 2 decimal digits.DecimalNumber(int decimals) Create a decimal number of value 0.DecimalNumber(DecimalNumber number) Construct a decimal number from another one.DecimalNumber(String value) Create a decimal number.DecimalNumber(String value, int decimals) Create a decimal number.DecimalNumber(BigDecimal value) Construct a decimal number from a BigDecimal.DecimalNumber(BigDecimal value, int decimals) Construct a decimal number from a BigDecimal. -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckLimit(String name, int width) intcompareTo(DecimalNumber number) static DecimalNumberstatic DecimalNumberbooleangetAverageValue(DecimalNumber second) getAverageValue(BigDecimal second) intGet the storable value.getValue()Get the decimal number as BigDecimal.inthashCode()booleanisSameValue(DecimalNumber another) booleanisSameValue(BigDecimal another) booleanisSameValue(BigInteger another) booleanisZero()toString()toString(int decimals) Convert it into a String with at least minimum decimals places specified.zero()static DecimalNumberzero(int decimals)
-
Field Details
-
ZERO
-
value
-
-
Constructor Details
-
DecimalNumber
public DecimalNumber()Create a decimal number of value 0 with 2 decimal digits. -
DecimalNumber
public DecimalNumber(int decimals) Create a decimal number of value 0.- Parameters:
decimals- Number of decimal places
-
DecimalNumber
Create a decimal number. Number of decimal places will be taken from what is defined in the value.- Parameters:
value- The value
-
DecimalNumber
Create a decimal number.- Parameters:
value- The valuedecimals- Number of decimal places
-
DecimalNumber
Construct a decimal number from another one.- Parameters:
number- The decimal number to be set.
-
DecimalNumber
Construct a decimal number from a BigDecimal. Number of decimal places will be taken from what is defined in the value.- Parameters:
value- The BigDecimal value.
-
DecimalNumber
Construct a decimal number from a BigDecimal.- Parameters:
value- The BigDecimal value.decimals- Number of decimal places
-
-
Method Details
-
create
-
create
-
zero
-
getValue
-
equals
-
hashCode
-
toString
-
toString
Convert it into a String with at least minimum decimals places specified.Example: Value: 4123.4500, Output: "4123.4500" (if decimals is les than zero, no conversion), "4123.450000" (for 6 decimals), "4123.45" (for 2 decimals or less)
Example: Value: 4123.0000, Output: "4123.0000" (if decimals is les than zero, no conversion), "4123.000000" (for 6 decimals), "4123.00" (for 2 decimals), "4123" (if decimals is zero)
- Parameters:
decimals- Number of minimum decimals required in the output.- Returns:
- String value.
-
getStorableValue
Description copied from interface:StorableGet the storable value. By default,Object.toString()is returned.- Specified by:
getStorableValuein interfaceStorable- Returns:
- Storable value as a string.
-
compareTo
- Specified by:
compareToin interfaceComparable<DecimalNumber>
-
isZero
public boolean isZero() -
getDecimals
public int getDecimals() -
zero
-
checkLimit
- Throws:
Invalid_Value
-
getAverageValue
-
getAverageValue
-
isSameValue
-
isSameValue
-
isSameValue
-