net.commerce.zocalo.currency
Class Price
java.lang.Object
net.commerce.zocalo.currency.Quantity
net.commerce.zocalo.currency.RangedQuantity
net.commerce.zocalo.currency.Price
- All Implemented Interfaces:
- java.lang.Comparable
public class Price
- extends RangedQuantity
Prices have a quantity, a maximum, and a scale. The Maximum is the
maximum price in some market, the scale tells how to scale prices for printing (when
holdings are in dollars and prices are in cents, scale would be 2.)
RoundingMode wants PRECISION instead of SCALE, so we have to be careful in converting.
We want to know how many digits to the right of the decimal place to maintain in
various operations (SCALE). PRECISION means how many significant digits in total,
not how many to the right of the decimal. BigDecimal uses SCALE the way we want, but
we have to be careful to round with movePointLeft(x).newScale(0).
Need maxPrice, conversion for Currency scale. (Plus computation resolution)
Example:
1-99, 0, 0 (Chapman experiments)
.01-99.99, -2, 0 (holdings should print to .00)
1-399, 0, 0 (Chapman experiments)
.1-99.9, -1, 0 (InTrade)
1-99, 0, 0 (NewsFutures)
Methods inherited from class net.commerce.zocalo.currency.Quantity |
abs, absLog, approaches, asValue, compareTo, div, div, exp, floor, getId, getQuant, isNegative, isNegligible, isNonNegative, isPositive, isZero, max, min, minus, movePointLeft, newScale, plus, printAsDetailedQuantity, printAsDollars, printAsIntegerQuantity, printAsQuantity, printAsScore, remainder, round, roundFloor, scale, setId, setQuant, times |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
ONE_DOLLAR
public static final Price ONE_DOLLAR
ZERO_DOLLARS
public static final Price ZERO_DOLLARS
Price
public Price(java.math.BigDecimal q,
Price prior)
Price
public Price(double q,
Price prior)
Price
public Price(java.lang.String q,
Price prior)
Price
public Price(Quantity q,
Price prior)
Price
public Price(Quantity price,
Quantity max)
Price
public Price(Quantity priceLimit)
dollarPrice
public static Price dollarPrice(java.lang.String p)
dollarPrice
public static Price dollarPrice(double p)
negate
public Quantity negate()
- Overrides:
negate
in class Quantity
asProbability
public Probability asProbability()
- Overrides:
asProbability
in class RangedQuantity
printQuant
public java.lang.String printQuant()
inverted
public Price inverted()
- Specified by:
inverted
in class RangedQuantity
round
public Price round(java.math.MathContext c)
- Specified by:
round
in class RangedQuantity
newValue
public Price newValue(Quantity quantity)
- Specified by:
newValue
in class RangedQuantity
newValue
public Price newValue(java.math.BigDecimal quantity)
- Specified by:
newValue
in class RangedQuantity
simplify
public Price simplify()
- Overrides:
simplify
in class Quantity
compareTo
public int compareTo(Quantity quantity)
- Overrides:
compareTo
in class Quantity
printAsWholeCents
public java.lang.String printAsWholeCents()
printHighPrecision
public java.lang.String printHighPrecision()
toString
public java.lang.String toString()
- Overrides:
toString
in class Quantity