@Immutable @LevelUpApi(contract=PUBLIC) @NonWrappable public final class MonetaryValue extends Object implements Parcelable
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<MonetaryValue> |
CREATOR
Implements the
Parcelable interface. |
protected static String |
USD_CODE
The currency code for USD.
|
protected static String |
USD_SYMBOL
The symbol for USD.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
MonetaryValue(long amount)
Constructor.
|
MonetaryValue(long amount,
String currencyCode,
String currencySymbol) |
Modifier and Type | Method and Description |
---|---|
int |
describeContents() |
boolean |
equals(Object o) |
long |
getAmount()
The amount (in cents) for this
MonetaryValue . |
String |
getCurrencyCode()
The raw currency code, such as "USD" or "EUR".
|
String |
getCurrencySymbol()
The currency symbol (i.e.: "$" or "€").
|
String |
getFormattedAmountWithCurrencySymbol(Context context)
Get the formatted currency amount with symbol, assuming standard US/European "symbol+amount"
formatting.
|
String |
getFormattedCentStrippedAmountWithCurrencySymbol(Context context)
Get the formatted currency amount with symbol, assuming standard US/European "symbol+amount"
formatting; drop the last digits and decimal/comma if they're all 0s.
|
static String |
getFormattedMoney(Context context,
String currencySymbol,
long amount)
Helper to format a long monetary value to a string.
|
static String |
getFormattedMoneyNoDecimal(Context context,
String currencySymbol,
long amount)
Helper to format a monetary value to a string, but truncate the decimals.
|
int |
hashCode() |
String |
toString() |
void |
writeToParcel(Parcel dest,
int flags) |
public static final Parcelable.Creator<MonetaryValue> CREATOR
Parcelable
interface.@VisibleForTesting(visibility=PRIVATE) protected static final String USD_CODE
@VisibleForTesting(visibility=PRIVATE) protected static final String USD_SYMBOL
public MonetaryValue(long amount)
amount
- the amount (in cents) for this MonetaryValue
.public int describeContents()
describeContents
in interface Parcelable
public void writeToParcel(Parcel dest, int flags)
writeToParcel
in interface Parcelable
public String getFormattedAmountWithCurrencySymbol(Context context)
context
- the Application context.public String getFormattedCentStrippedAmountWithCurrencySymbol(Context context)
context
- the Application context.public static String getFormattedMoney(Context context, String currencySymbol, long amount)
context
- the Application context.currencySymbol
- the symbol for the currency of the money.amount
- the amount of money.String
with the formatted amount.public static String getFormattedMoneyNoDecimal(Context context, String currencySymbol, long amount)
context
- the Application context.currencySymbol
- the symbol for the currency of the money.amount
- the amount of money.String
with the formatted amount rounded to the nearest whole dollar, with no
cents.public long getAmount()
MonetaryValue
.public String getCurrencyCode()
public String getCurrencySymbol()