Skip to main content

steps_to_value

Function steps_to_value 

Source
pub fn steps_to_value(
    steps: i64,
    step: Decimal,
) -> Result<Decimal, PrecisionError>
Expand description

Converts a whole number of steps back to a value, exactly: 2001 steps of 0.05 is 100.05.

§Errors

PrecisionError::InvalidStep if the step is zero or negative, PrecisionError::StepsOverflow if the product does not fit.

§Examples

use brokapi_bcs_protocol::utils::precision::steps_to_value;
use rust_decimal::Decimal;

assert_eq!(steps_to_value(2001, Decimal::new(5, 2))?, Decimal::new(10005, 2));
assert_eq!(steps_to_value(3, Decimal::new(1, 3))?, Decimal::new(3, 3));