/// Converts a string to the internal binary format. Please note, this is a decimal
/// format, not a floating-point one.
///
/// - https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/impl/STAmount.cpp#L781
/// - https://github.com/XRPLF/xrpl-py/blob/master/xrpl/core/binarycodec/types/amount.py#L141
Converts a string to the internal binary format. Please note, this is a decimal
format, not a floating-point one.


Converts a string to the internal binary format . Please note this is a decimal format not a floating - point one .
pub fn internal_number_from_string(s: &str) -> u64 {
    // TODO: handle sign
    // TODO: handle zero case
    // TODO: handle integer case
    // TODO: handle unwraps!
    if s == "0" || s == "0.0" {
        // Special case for zero value.
        return 0b1000000000000000000000000000000000000000000000000000000000000000;
    }
    let mut mantissa: i64;
    let mut exponent: i64;
    if s.contains('.') {
        let (integer, decimal) = s.split_once('.').unwrap();
        mantissa = format!("{}{}", integer, decimal).parse().unwrap();
        exponent = -(decimal.len() as i64);
    } else {
        mantissa = s.parse().unwrap();
        exponent = 0;
    }
    // let (integer, decimal) = s.split_once('.').unwrap();
    // let mut mantissa: i64 = format!("{}{}", integer, decimal).parse().unwrap();
    // let mut exponent: i64 = -(decimal.len() as i64);
    // Normalize to expected range.
    while mantissa < MIN_MANTISSA && exponent > MIN_IOU_EXPONENT {
        mantissa *= 10;
        exponent -= 1;
    }
    while mantissa > MAX_MANTISSA {
        if exponent < MAX_IOU_EXPONENT {
            mantissa /= 10;
            exponent += 1;
        }
    }
    if exponent < MIN_IOU_EXPONENT || mantissa < MIN_MANTISSA {
        // Round to zero.
        return 0b1000000000000000000000000000000000000000000000000000000000000000;
    }
    // TODO:
    //
    // if exp > _MAX_IOU_EXPONENT or mantissa > _MAX_MANTISSA:
    //     raise XRPLBinaryCodecException(
    //         f"Amount overflow in issued currency value {str(value)}"
    //     )
    // bit 63: 1 = not XRP
    // bit 62: 1 = positive
    let mask = 0b1100000000000000000000000000000000000000000000000000000000000000;
    let mantissa = mantissa as u64;
    let exponent = (97 + exponent) as u64;
    mantissa | (exponent << 54) | mask
}
pub fn internal_number_from_string ( s : & str ) -> u64 { // TODO: handle sign // TODO: handle zero case // TODO: handle integer case // TODO: handle unwraps! if s == " " || s == " " { // Special case for zero value. return 0b1000000000000000000000000000000000000000000000000000000000000000 ; } let mut mantissa : i64 ; let mut exponent : i64 ; if s . contains ( '.' ) { let ( integer , decimal ) = s . split_once ( '.' ) . unwrap ( ) ; mantissa = format ! ( " " integer decimal ) . parse ( ) . unwrap ( ) ; exponent = - ( decimal . len ( ) as i64 ) ; } else { mantissa = s . parse ( ) . unwrap ( ) ; exponent = 0 ; } // let (integer, decimal) = s.split_once('.').unwrap(); // let mut mantissa: i64 = format!("{}{}", integer, decimal).parse().unwrap(); // let mut exponent: i64 = -(decimal.len() as i64); // Normalize to expected range. while mantissa < MIN_MANTISSA && exponent > MIN_IOU_EXPONENT { mantissa *= 10 ; exponent -= 1 ; } while mantissa > MAX_MANTISSA { if exponent < MAX_IOU_EXPONENT { mantissa /= 10 ; exponent += 1 ; } } if exponent < MIN_IOU_EXPONENT || mantissa < MIN_MANTISSA { // Round to zero. return 0b1000000000000000000000000000000000000000000000000000000000000000 ; } // TODO: // // if exp > _MAX_IOU_EXPONENT or mantissa > _MAX_MANTISSA: //     raise XRPLBinaryCodecException( //         f"Amount overflow in issued currency value {str(value)}" //     ) // bit 63: 1 = not XRP // bit 62: 1 = positive let mask = 0b1100000000000000000000000000000000000000000000000000000000000000 ; let mantissa = mantissa as u64 ; let exponent = ( 97 + exponent ) as u64 ; mantissa | ( exponent << 54 ) | mask }
Converts a string to the internal binary format.
Converts a string to the internal binary format .
s
&str