Skip to main content

DecimalConvert

Trait DecimalConvert 

Source
pub trait DecimalConvert: DecimalArithmetic {
    // Required methods
    fn from_bits(raw: Self::Storage) -> Self;
    fn to_bits(self) -> Self::Storage;
    fn scale(self) -> u32;
    fn to_int(self) -> i64;
    fn to_int_with(self, mode: RoundingMode) -> i64;
    fn from_f64(value: f64) -> Self;
    fn from_f64_with(value: f64, mode: RoundingMode) -> Self;
    fn to_f64(self) -> f64;
    fn to_f32(self) -> f32;
}
Expand description

Round-trip + conversion surface shared by every decimal width.

Supertraits DecimalArithmetic so the storage type and boundary constants are accessible for saturation logic.

Required Methods§

Source

fn from_bits(raw: Self::Storage) -> Self

Constructs from a raw storage value.

Source

fn to_bits(self) -> Self::Storage

Returns the raw storage value.

Source

fn scale(self) -> u32

Returns the decimal scale of this value.

Source

fn to_int(self) -> i64

Convert to i64 using the crate-default rounding mode.

Source

fn to_int_with(self, mode: RoundingMode) -> i64

Convert to i64 using the supplied rounding mode.

Source

fn from_f64(value: f64) -> Self

Construct from f64 using the crate-default rounding mode.

Source

fn from_f64_with(value: f64, mode: RoundingMode) -> Self

Construct from f64 using the supplied rounding mode.

Source

fn to_f64(self) -> f64

Convert to f64. Lossy when the storage magnitude exceeds f64’s ~15-digit exact range.

Source

fn to_f32(self) -> f32

Convert to f32. Lossy.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<const SCALE: u32> DecimalConvert for D18<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D38<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D57<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D76<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D115<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D153<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D230<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D307<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D462<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D616<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D924<SCALE>

Source§

impl<const SCALE: u32> DecimalConvert for D1232<SCALE>