pub struct Decimal { /* private fields */ }Expand description
Número decimal de ponto fixo: mantissa × 10^-scale. Exato para dinheiro.
Implementations§
Source§impl Decimal
impl Decimal
pub const ZERO: Decimal
pub fn mantissa(&self) -> i128
pub fn scale(&self) -> u8
Sourcepub fn parse(text: &str) -> Option<Decimal>
pub fn parse(text: &str) -> Option<Decimal>
Lê "-1234.56" (separador decimal ., sem separador de milhar).
Sourcepub fn parse_with(text: &str, decimal_separator: char) -> Option<Decimal>
pub fn parse_with(text: &str, decimal_separator: char) -> Option<Decimal>
Lê com o separador decimal dado (sem separador de milhar).
Sourcepub fn from_f64(value: f64, scale: u8) -> Option<Decimal>
pub fn from_f64(value: f64, scale: u8) -> Option<Decimal>
Converte arredondando para scale casas.
pub fn to_f64(&self) -> f64
pub fn to_i64(&self) -> Option<i64>
Sourcepub fn rescale(&self, scale: u8) -> Decimal
pub fn rescale(&self, scale: u8) -> Decimal
Muda o número de casas, arredondando metade para longe do zero. Entra em pânico se o
número não couber (só com valores perto de 10³⁸); para tratar, checked_rescale.
Sourcepub fn checked_rescale(&self, scale: u8, mode: Rounding) -> Option<Decimal>
pub fn checked_rescale(&self, scale: u8, mode: Rounding) -> Option<Decimal>
Muda o número de casas, arredondando do jeito mode; None se não couber.
Sourcepub fn round(&self, scale: u8, mode: Rounding) -> Option<Decimal>
pub fn round(&self, scale: u8, mode: Rounding) -> Option<Decimal>
Arredonda para scale casas do jeito mode (o RoundTo do Delphi, com o modo).
pub fn checked_add(&self, other: &Decimal) -> Option<Decimal>
pub fn checked_sub(&self, other: &Decimal) -> Option<Decimal>
Sourcepub fn checked_mul(&self, other: &Decimal) -> Option<Decimal>
pub fn checked_mul(&self, other: &Decimal) -> Option<Decimal>
O produto exato (as casas somam); se passar de MAX_SCALE, arredonda metade para
cima até caber.
Sourcepub fn checked_div(
&self,
other: &Decimal,
scale: u8,
mode: Rounding,
) -> Option<Decimal>
pub fn checked_div( &self, other: &Decimal, scale: u8, mode: Rounding, ) -> Option<Decimal>
A divisão exata com scale casas no resultado, arredondada do jeito mode (sem passar
por f64: 0,30 / 0,10 = 3). None se other é zero ou se não couber.
Sourcepub fn default_div_scale(&self, other: &Decimal) -> u8
pub fn default_div_scale(&self, other: &Decimal) -> u8
As casas da divisão quando ninguém diz quantas: as do maior dos dois mais 4, como o
Currency do Delphi (100,00 / 3 = 33,333333).
pub fn is_negative(&self) -> bool
Trait Implementations§
Source§impl Add for Decimal
Os operadores, como o Currency do Delphi. Estouro entra em pânico (como os inteiros);
para tratar, os checked_*. A divisão usa Decimal::default_div_scale e arredonda
metade para cima; dividir por zero entra em pânico.
impl Add for Decimal
Os operadores, como o Currency do Delphi. Estouro entra em pânico (como os inteiros);
para tratar, os checked_*. A divisão usa Decimal::default_div_scale e arredonda
metade para cima; dividir por zero entra em pânico.
impl Copy for Decimal
impl Eq for Decimal
Source§impl Ord for Decimal
impl Ord for Decimal
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Auto Trait Implementations§
impl Forget for Decimal
impl Freeze for Decimal
impl Move for Decimal
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnsafeUnpin for Decimal
impl UnwindSafe for Decimal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.