Skip to main content

ToRound

Trait ToRound 

Source
pub trait ToRound {
    // Required methods
    fn round(&self) -> Decimal;
    fn round_to(&self, decimal_places: u32) -> Decimal;
}
Expand description

Trait for rounding operations on numeric types, specifically for financial calculations.

This trait provides methods to round a number to the nearest integer and to a specified number of decimal places, ensuring precision and accuracy in financial computations.

Required Methods§

Source

fn round(&self) -> Decimal

Rounds the number to the nearest integer.

This method rounds the number to the nearest whole number, removing any fractional part.

Source

fn round_to(&self, decimal_places: u32) -> Decimal

Rounds the number to a specified number of decimal places.

This method rounds the number to the specified number of digits after the decimal point, providing control over the precision of the rounded value.

§Arguments
  • decimal_places - The number of decimal places to round to.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§