pub struct Decimal(/* private fields */);
Expand description
A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0
The greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)
Implementations§
Source§impl Decimal
impl Decimal
pub const MAX: Self
Sourcepub fn from_ratio(
numerator: impl Into<Uint128>,
denominator: impl Into<Uint128>,
) -> Self
pub fn from_ratio( numerator: impl Into<Uint128>, denominator: impl Into<Uint128>, ) -> Self
Returns the ratio (numerator / denominator) as a Decimal
pub fn is_zero(&self) -> bool
Sourcepub fn checked_mul(self, other: Self) -> StdResult<Self>
pub fn checked_mul(self, other: Self) -> StdResult<Self>
Multiply ‘self’ by ‘other’. Function can return errors such as:
- OverflowError from multiplication,
- ConversionOverflowError during Uint256 to Uint128 conversion.
Sourcepub fn checked_div(self, other: Self) -> StdResult<Self>
pub fn checked_div(self, other: Self) -> StdResult<Self>
Divide ‘self’ by ‘other’. Function can return errors such as:
- OverflowError from multiplication,
- DivideByZeroError if ‘other’ is equal to 0,
- ConversionOverflowError during Uint256 to Uint128 conversion.
Sourcepub fn divide_uint128_by_decimal(a: Uint128, b: Decimal) -> StdResult<Uint128>
pub fn divide_uint128_by_decimal(a: Uint128, b: Decimal) -> StdResult<Uint128>
Divide Uint128 by Decimal. (Uint128 / numerator / denominator) is equal to (Uint128 * denominator / numerator).
Sourcepub fn divide_uint128_by_decimal_and_ceil(
a: Uint128,
b: Decimal,
) -> StdResult<Uint128>
pub fn divide_uint128_by_decimal_and_ceil( a: Uint128, b: Decimal, ) -> StdResult<Uint128>
Divide Uint128 by Decimal, rounding up to the nearest integer.
Sourcepub fn multiply_uint128_by_decimal_and_ceil(
a: Uint128,
b: Decimal,
) -> StdResult<Uint128>
pub fn multiply_uint128_by_decimal_and_ceil( a: Uint128, b: Decimal, ) -> StdResult<Uint128>
Multiply Uint128 by Decimal, rounding up to the nearest integer.
pub fn to_std_decimal(&self) -> StdDecimal
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Decimal
Deserializes as a base64 string
impl<'de> Deserialize<'de> for Decimal
Deserializes as a base64 string
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl DivAssign<Uint128> for Decimal
impl DivAssign<Uint128> for Decimal
Source§fn div_assign(&mut self, rhs: Uint128)
fn div_assign(&mut self, rhs: Uint128)
/=
operation. Read moreSource§impl From<Decimal> for Decimal
impl From<Decimal> for Decimal
Source§fn from(std_decimal: StdDecimal) -> Decimal
fn from(std_decimal: StdDecimal) -> Decimal
Source§impl FromStr for Decimal
impl FromStr for Decimal
Source§impl JsonSchema for Decimal
impl JsonSchema for Decimal
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moreSource§impl Mul<Decimal> for Uint128
Both du and ud with d: Decimal and u: Uint128 returns an Uint128. There is no
specific reason for this decision other than the initial use cases we have. If you
need a Decimal result for the same calculation, use Decimal(du) or Decimal(ud).
impl Mul<Decimal> for Uint128
Both du and ud with d: Decimal and u: Uint128 returns an Uint128. There is no specific reason for this decision other than the initial use cases we have. If you need a Decimal result for the same calculation, use Decimal(du) or Decimal(ud).