Struct solana_maths::Decimal
source · [−]pub struct Decimal(pub U192);
Expand description
Large decimal values, precise to 18 digits
Tuple Fields
0: U192
Implementations
sourceimpl Decimal
impl Decimal
sourcepub fn from_percent(percent: u8) -> Self
pub fn from_percent(percent: u8) -> Self
Create scaled decimal from percent value
pub fn from_bips(percent: u64) -> Self
sourcepub fn to_scaled_val(&self) -> Result<u128, ProgramError>
pub fn to_scaled_val(&self) -> Result<u128, ProgramError>
Return raw scaled value if it fits within u128
sourcepub fn from_scaled_val(scaled_val: u128) -> Self
pub fn from_scaled_val(scaled_val: u128) -> Self
Create decimal from scaled value
sourcepub fn try_round_u64(&self) -> Result<u64, ProgramError>
pub fn try_round_u64(&self) -> Result<u64, ProgramError>
Round scaled decimal to u64
sourcepub fn try_ceil_u64(&self) -> Result<u64, ProgramError>
pub fn try_ceil_u64(&self) -> Result<u64, ProgramError>
Ceiling scaled decimal to u64
sourcepub fn try_floor_u64(&self) -> Result<u64, ProgramError>
pub fn try_floor_u64(&self) -> Result<u64, ProgramError>
Floor scaled decimal to u64
Trait Implementations
sourceimpl Ord for Decimal
impl Ord for Decimal
sourceimpl Pack for Decimal
impl Pack for Decimal
sourcefn get_packed_len() -> usize
fn get_packed_len() -> usize
Get the packed length
sourcefn unpack(input: &[u8]) -> Result<Self, ProgramError> where
Self: IsInitialized,
fn unpack(input: &[u8]) -> Result<Self, ProgramError> where
Self: IsInitialized,
Unpack from slice and check if initialized
sourcefn unpack_unchecked(input: &[u8]) -> Result<Self, ProgramError>
fn unpack_unchecked(input: &[u8]) -> Result<Self, ProgramError>
Unpack from slice without checking if initialized
sourceimpl PartialOrd<Decimal> for Decimal
impl PartialOrd<Decimal> for Decimal
sourcefn partial_cmp(&self, other: &Decimal) -> Option<Ordering>
fn partial_cmp(&self, other: &Decimal) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl TryDiv<Decimal> for Decimal
impl TryDiv<Decimal> for Decimal
sourcefn try_div(self, rhs: Self) -> Result<Self, ProgramError>
fn try_div(self, rhs: Self) -> Result<Self, ProgramError>
Divide
sourceimpl TryDiv<Rate> for Decimal
impl TryDiv<Rate> for Decimal
sourcefn try_div(self, rhs: Rate) -> Result<Self, ProgramError>
fn try_div(self, rhs: Rate) -> Result<Self, ProgramError>
Divide
sourceimpl TryDiv<u64> for Decimal
impl TryDiv<u64> for Decimal
sourcefn try_div(self, rhs: u64) -> Result<Self, ProgramError>
fn try_div(self, rhs: u64) -> Result<Self, ProgramError>
Divide
sourceimpl TryMul<Decimal> for Decimal
impl TryMul<Decimal> for Decimal
sourcefn try_mul(self, rhs: Self) -> Result<Self, ProgramError>
fn try_mul(self, rhs: Self) -> Result<Self, ProgramError>
Multiply
sourceimpl TryMul<Rate> for Decimal
impl TryMul<Rate> for Decimal
sourcefn try_mul(self, rhs: Rate) -> Result<Self, ProgramError>
fn try_mul(self, rhs: Rate) -> Result<Self, ProgramError>
Multiply
sourceimpl TryMul<u64> for Decimal
impl TryMul<u64> for Decimal
sourcefn try_mul(self, rhs: u64) -> Result<Self, ProgramError>
fn try_mul(self, rhs: u64) -> Result<Self, ProgramError>
Multiply
sourceimpl TrySub for Decimal
impl TrySub for Decimal
sourcefn try_sub(self, rhs: Self) -> Result<Self, ProgramError>
fn try_sub(self, rhs: Self) -> Result<Self, ProgramError>
Subtract
impl Copy for Decimal
impl Eq for Decimal
impl Sealed for Decimal
impl StructuralEq for Decimal
impl StructuralPartialEq for Decimal
Auto Trait Implementations
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnwindSafe for Decimal
Blanket Implementations
impl<T> AbiExample for T
impl<T> AbiExample for T
default fn example() -> T
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more