Class Currency
The XRP Ledger has two kinds of digital asset: XRP and tokens.
Both types have high precision, although their formats are different
Inheritance
Namespace: Xrpl.Models.Common
Assembly: Xrpl.dll
Syntax
public class Currency
Constructors
| Edit this page View SourceCurrency()
base constructor.
Declaration
public Currency()
Properties
| Edit this page View SourceCurrencyCode
The standard format for currency codes is a three-character string such as USD.
This is intended for use with ISO 4217 Currency Codes
As a 160-bit hexadecimal string, such as "0158415500000000C1F76FF6ECB0BAC600000000".
The following characters are permitted:
all uppercase and lowercase letters, digits, as well as the symbols ? ! @ # $ % ^ * ( ) { } [ ] | and symbols ampersand, less, greater
Currency codes are case-sensitive.
Declaration
[JsonPropertyName("currency")]
public string CurrencyCode { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
CurrencyValidName
Readable currency name
Declaration
[JsonIgnore]
public string CurrencyValidName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Issuer
Generally, the account that issues this token.
In special cases, this can refer to the account that holds the token instead.
Declaration
[JsonPropertyName("issuer")]
public string Issuer { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
MPTokenIssuanceID
The ID of the MPT to authorize.
Declaration
[JsonPropertyName("mpt_issuance_id")]
public string MPTokenIssuanceID { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Value
Quoted decimal representation of the amount of the token.
This can include scientific notation, such as 1.23e11 meaning 123,000,000,000.
Both e and E may be used.
This can be negative when displaying balances, but negative values are disallowed in other contexts such as specifying how much to send.
Declaration
[JsonPropertyName("value")]
public string Value { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
ValueAsNumber
decimal currency amount (drops for XRP)
Declaration
[JsonIgnore]
public decimal ValueAsNumber { get; set; }
Property Value
| Type | Description |
|---|---|
| decimal |
Remarks
decimal does not cover the range XRPL allows an issued currency: the ledger
reaches roughly 1e96 and down to 1e-81, this type stops at about
7.9e28. Amounts above that throw AmountOutOfRangeException rather than
being answered with a number that is not the one the node sent.
Amounts below 1e-28 return zero instead of throwing, and the asymmetry is deliberate.
A balance of 1e-81 rounded to zero is zero at any scale a caller can act on, so
failing over it would cost more than it protects; an amount of 1e96 reported as
7.9e28 is wrong by 67 orders of magnitude and is worth stopping for.
Writing rounds to the ledger's sixteen significant digits; the binary codec, given a string
with more than sixteen, refuses it outright. That looks inconsistent and is not: the two see
different inputs. A string with seventeen digits cannot arrive from the network - rippled
normalises the mantissa into [1e15, 1e16) before serialising - so the codec only ever
meets one a caller wrote by hand, where refusing is right. This setter meets a computed
decimal, which routinely carries 28 digits: AmmMath
returns such values. Rounding them is the service, not a loss.
Exceptions
| Type | Condition |
|---|---|
| AmountOutOfRangeException | The amount exceeds what decimal can hold. |
| FormatException | The amount is not a number at all. |
ValueAsXrp
XRP token amount (non drops value)
Declaration
[JsonIgnore]
public decimal? ValueAsXrp { get; set; }
Property Value
| Type | Description |
|---|---|
| decimal? |
Methods
| Edit this page View SourceEquals(object)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o |
Returns
| Type | Description |
|---|---|
| bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
ToString()
A readable form of the amount.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Remarks
Falls back to the raw Value for an amount outside what decimal can hold, rather than letting ValueAsNumber throw through it. By convention object.ToString() does not throw, and the places it is called from - logging, string interpolation, a debugger's watch window - are exactly where someone would be while working out why an amount is unusual. Failing there hides the value instead of showing it.
Operators
| Edit this page View Sourceoperator ==(Currency?, Currency?)
Declaration
public static bool operator ==(Currency? left, Currency? right)
Parameters
| Type | Name | Description |
|---|---|---|
| Currency | left | |
| Currency | right |
Returns
| Type | Description |
|---|---|
| bool |
implicit operator Currency(decimal)
Implicit conversion from decimal → Currency
Declaration
public static implicit operator Currency(decimal value)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | value |
Returns
| Type | Description |
|---|---|
| Currency | currency |
implicit operator Currency(double)
Implicit conversion from double → Currency
Declaration
public static implicit operator Currency(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | value |
Returns
| Type | Description |
|---|---|
| Currency | currency |
implicit operator Currency(int)
Implicit conversion from int → Currency
Declaration
public static implicit operator Currency(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | value |
Returns
| Type | Description |
|---|---|
| Currency | currency |
implicit operator Currency(string)
Implicit conversion from string → Currency
Declaration
public static implicit operator Currency(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | value |
Returns
| Type | Description |
|---|---|
| Currency | currency |
implicit operator Currency(uint)
Implicit conversion from uint → Currency
Declaration
public static implicit operator Currency(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | value |
Returns
| Type | Description |
|---|---|
| Currency | currency |
operator !=(Currency?, Currency?)
Declaration
public static bool operator !=(Currency? left, Currency? right)
Parameters
| Type | Name | Description |
|---|---|---|
| Currency | left | |
| Currency | right |
Returns
| Type | Description |
|---|---|
| bool |