pub fn try_ui_amount_into_amount(
        &self,
        ui_amount: &str,
        decimals: u8,
        unix_timestamp: i64,
    ) -> Result<u64, ProgramError> {
        let scaled_amount = ui_amount
            .parse::<f64>()
            .map_err(|_| ProgramError::InvalidArgument)?;
        let amount = scaled_amount
            / self
                .total_scale(decimals, unix_timestamp)
                .ok_or(ProgramError::InvalidArgument)?;
        if amount > (u64::MAX as f64) || amount < (u64::MIN as f64) || amount.is_nan() {
            Err(ProgramError::InvalidArgument)
        } else {
            Ok(amount.round() as u64) // this is important, if you round earlier, you'll get wrong "inf" answers
        }
    }
/// Try to convert a UI represenation of a token amount to its raw amount using the given decimals
/// field
Try to convert a UI represenation of a token amount to its raw amount using the given decimals
field
Try to convert a UI represenation of a token amount to its raw amount using the given decimals field
pub fn try_ui_amount_into_amount(
        &self,
        ui_amount: &str,
        decimals: u8,
        unix_timestamp: i64,
    ) -> Result<u64, ProgramError> {
        let scaled_amount = ui_amount
            .parse::<f64>()
            .map_err(|_| ProgramError::InvalidArgument)?;
        let amount = scaled_amount
            / self
                .total_scale(decimals, unix_timestamp)
                .ok_or(ProgramError::InvalidArgument)?;
        if amount > (u64::MAX as f64) || amount < (u64::MIN as f64) || amount.is_nan() {
            Err(ProgramError::InvalidArgument)
        } else {
            Ok(amount.round() as u64) // this is important, if you round earlier, you'll get wrong "inf" answers
        }
    }
pub fn try_ui_amount_into_amount ( & self , ui_amount : & str , decimals : u8 , unix_timestamp : i64 , ) -> Result < u64 , ProgramError > { let scaled_amount = ui_amount . parse :: < f64 > ( ) . map_err ( | _ | ProgramError :: InvalidArgument ) ? ; let amount = scaled_amount / self . total_scale ( decimals , unix_timestamp ) . ok_or ( ProgramError :: InvalidArgument ) ? ; if amount > ( u64 :: MAX as f64 ) || amount < ( u64 :: MIN as f64 ) || amount . is_nan ( ) { Err ( ProgramError :: InvalidArgument ) } else { Ok ( amount . round ( ) as u64 ) // this is important, if you round earlier, you'll get wrong "inf" answers } }
Try to convert a UI represenation of a token amount to its raw amount using the given decimals
field
Try to convert a UI represenation of a token amount to its raw amount using the given decimals field
&self
ui_amount
&str
decimals
u8
unix_timestamp
i64
&self
ui_amount
&str
decimals
u8
unix_timestamp
i64