Struct bitcoin::util::amount::SignedAmount [−][src]
pub struct SignedAmount(_);
Expand description
SignedAmount
The SignedAmount type can be used to express Bitcoin amounts that supports arithmetic and conversion to various denominations.
Warning!
This type implements several arithmetic operations from core::ops.
To prevent errors due to overflow or underflow when using these operations,
it is advised to instead use the checked arithmetic methods whose names
start with checked_
. The operations from core::ops that Amount
implements will panic when overflow or underflow occurs.
Implementations
The zero amount.
Exactly one satoshi.
Exactly one bitcoin.
Create an SignedAmount with satoshi precision and the given number of satoshis.
Get the number of satoshis in this SignedAmount.
The maximum value of an SignedAmount.
The minimum value of an SignedAmount.
Convert from a value expressing bitcoins to an SignedAmount.
Parse a decimal string as a value in the given denomination.
Note: This only parses the value string. If you want to parse a value with denomination, use FromStr.
Parses amounts with denomination suffix like they are produced with Self::to_string_with_denomination or with fmt::Display. If you want to parse only the amount without the denomination, use Self::from_str_in.
Express this SignedAmount as a floating-point value in the given denomination.
Please be aware of the risk of using floating-point numbers.
Express this SignedAmount as a floating-point value in Bitcoin.
Equivalent to to_float_in(Denomination::Bitcoin)
.
Please be aware of the risk of using floating-point numbers.
pub fn from_float_in(
value: f64,
denom: Denomination
) -> Result<SignedAmount, ParseAmountError>
pub fn from_float_in(
value: f64,
denom: Denomination
) -> Result<SignedAmount, ParseAmountError>
Convert this SignedAmount in floating-point notation with a given denomination. Can return error if the amount is too big, too precise or negative.
Please be aware of the risk of using floating-point numbers.
Format the value of this SignedAmount in the given denomination.
Does not include the denomination.
Get a string number of this SignedAmount in the given denomination.
Does not include the denomination.
Get a formatted string of this SignedAmount in the given denomination, suffixed with the abbreviation for the denomination.
Get the absolute value of this SignedAmount.
Returns a number representing sign of this SignedAmount.
0
if the amount is zero1
if the amount is positive-1
if the amount is negative
Returns true
if this SignedAmount is positive and false
if
this SignedAmount is zero or negative.
Returns true
if this SignedAmount is negative and false
if
this SignedAmount is zero or positive.
Get the absolute value of this SignedAmount.
Returns None if overflow occurred. (self == min_value()
)
Checked addition. Returns None if overflow occurred.
Checked subtraction. Returns None if overflow occurred.
Checked multiplication. Returns None if overflow occurred.
Checked integer division. Be aware that integer division loses the remainder if no exact division can be made. Returns None if overflow occurred.
Checked remainder. Returns None if overflow occurred.
Subtraction that doesn’t allow negative SignedAmounts.
Returns None if either self, rhs
or the result is strictly negative.
Convert to an unsigned amount.
Trait Implementations
type Output = SignedAmount
type Output = SignedAmount
The resulting type after applying the +
operator.
Performs the +
operation. Read more
Performs the +=
operation. Read more
Performs the /=
operation. Read more
Performs the *=
operation. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Performs the %=
operation. Read more
type Output = SignedAmount
type Output = SignedAmount
The resulting type after applying the -
operator.
Performs the -
operation. Read more
Performs the -=
operation. Read more
Auto Trait Implementations
impl RefUnwindSafe for SignedAmount
impl Send for SignedAmount
impl Sync for SignedAmount
impl Unpin for SignedAmount
impl UnwindSafe for SignedAmount
Blanket Implementations
Mutably borrows from an owned value. Read more