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 from_i32(value: i32) -> Self;
    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 from_i32(value: i32) -> Self

Construct from an i32, scaling by 10^SCALE.

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", so this trait is not object safe.

Implementors§

Source§

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

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 D56<SCALE>

Source§

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

Source§

impl<const SCALE: u32> DecimalConvert for D114<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 D461<SCALE>

Source§

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

Source§

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

Source§

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