fn round(self, n_frac_digits: i8) -> Self {
        if n_frac_digits >= self.n_frac_digits as i8 {
            self
        } else if n_frac_digits < self.n_frac_digits as i8 - 38 {
            Self::ZERO
        } else {
            // n_frac_digits < self.n_frac_digits
            let shift: u8 = (self.n_frac_digits as i8 - n_frac_digits) as u8;
            let divisor = ten_pow(shift);
            let coeff = i128_div_rounded(self.coeff, divisor, None);
            if n_frac_digits >= 0 {
                Self {
                    coeff,
                    n_frac_digits: n_frac_digits as u8,
                }
            } else {
                // shift back
                Self {
                    coeff: coeff * ten_pow(-n_frac_digits as u8),
                    n_frac_digits: 0,
                }
            }
        }
    }
/// Returns a new `Decimal` with its value rounded to `n_frac_digits`
/// fractional digits according to the current [RoundingMode].
///
/// # Panics
///
/// Panics if the resulting value can not be represented by `Decimal`!
///
/// # Examples
///
/// ```rust
/// # use fpdec::{Dec, Decimal, Round};
/// let d = Dec!(28.27093);
/// let r = d.round(4);
/// assert_eq!(r.to_string(), "28.2709");
/// let r = d.round(1);
/// assert_eq!(r.to_string(), "28.3");
/// let r = d.round(0);
/// assert_eq!(r.to_string(), "28");
/// let r = d.round(-1);
/// assert_eq!(r.to_string(), "30");
/// ```
Returns a new `Decimal` with its value rounded to `n_frac_digits`
fractional digits according to the current [RoundingMode].
Returns a new ` Decimal ` with its value rounded to ` n_frac_digits ` fractional digits according to the current [ RoundingMode ] .
fn round(self, n_frac_digits: i8) -> Self {
        if n_frac_digits >= self.n_frac_digits as i8 {
            self
        } else if n_frac_digits < self.n_frac_digits as i8 - 38 {
            Self::ZERO
        } else {
            // n_frac_digits < self.n_frac_digits
            let shift: u8 = (self.n_frac_digits as i8 - n_frac_digits) as u8;
            let divisor = ten_pow(shift);
            let coeff = i128_div_rounded(self.coeff, divisor, None);
            if n_frac_digits >= 0 {
                Self {
                    coeff,
                    n_frac_digits: n_frac_digits as u8,
                }
            } else {
                // shift back
                Self {
                    coeff: coeff * ten_pow(-n_frac_digits as u8),
                    n_frac_digits: 0,
                }
            }
        }
    }
fn round ( self , n_frac_digits : i8 ) -> Self { if n_frac_digits >= self . n_frac_digits as i8 { self } else if n_frac_digits < self . n_frac_digits as i8 - 38 { Self :: ZERO } else { // n_frac_digits < self.n_frac_digits let shift : u8 = ( self . n_frac_digits as i8 - n_frac_digits ) as u8 ; let divisor = ten_pow ( shift ) ; let coeff = i128_div_rounded ( self . coeff , divisor , None ) ; if n_frac_digits >= 0 { Self { coeff , n_frac_digits : n_frac_digits as u8 , } } else { // shift back Self { coeff : coeff * ten_pow ( - n_frac_digits as u8 ) , n_frac_digits : 0 , } } } }
Returns a new `Decimal` with its value rounded to `n_frac_digits`
fractional digits according to the current [RoundingMode].
Returns a new ` Decimal ` with its value rounded to ` n_frac_digits ` fractional digits according to the current [ RoundingMode ] .
self
n_frac_digits
i8
panics
Panics if the resulting value can not be represented by `Decimal`!
Panics if the resulting value can not be represented by ` Decimal ` !
examples
None
use fpdec::{dec, decimal, round};
None