Skip to main content

precise_to_nearest

Function precise_to_nearest 

Source
pub fn precise_to_nearest(
    value: Decimal,
    step: Decimal,
) -> Result<Decimal, PrecisionError>
Expand description

Rounds a value to the nearest point of the step grid.

§Errors

The same as value_to_steps_nearest.

§Examples

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

let step = Decimal::new(5, 2);
assert_eq!(precise_to_nearest(Decimal::new(10102, 2), step)?, Decimal::new(10100, 2));
assert_eq!(precise_to_nearest(Decimal::new(10103, 2), step)?, Decimal::new(10105, 2));