pub struct SmallDecimal {
pub value: i64,
pub scale: i16,
pub negative: bool,
}Expand description
Small decimal structure for parsing/formatting without floats This avoids floating-point precision issues for financial data
Fields§
§value: i64The integer value (unscaled)
scale: i16The scale (number of decimal places)
negative: boolWhether the value is negative
Implementations§
Source§impl SmallDecimal
impl SmallDecimal
Sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Format as string with fixed scale (NORMATIVE)
Always render with exactly scale digits after decimal point.
Sourcepub fn from_str(s: &str, expected_scale: i16) -> Result<Self>
pub fn from_str(s: &str, expected_scale: i16) -> Result<Self>
Parse a decimal string into a SmallDecimal using the expected scale.
§Errors
Returns an error when the text violates the expected numeric format.
Sourcepub fn to_fixed_scale_string(&self, scale: i16) -> String
pub fn to_fixed_scale_string(&self, scale: i16) -> String
Format as string with the given fixed scale.
Always renders with exactly scale digits after the decimal point,
independent of the SmallDecimal’s own scale. Used for lossless JSON output.
Sourcepub fn format_to_scratch_buffer(&self, scale: i16, scratch_buffer: &mut String)
pub fn format_to_scratch_buffer(&self, scale: i16, scratch_buffer: &mut String)
Format the decimal into a caller-owned string buffer to avoid allocation.
This is the hot-path formatter used in COMP-3 JSON conversion. The buffer is cleared before writing.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Check if this decimal is negative
Sourcepub fn total_digits(&self) -> u16
pub fn total_digits(&self) -> u16
Get the total number of digits in this decimal
Trait Implementations§
Source§impl Clone for SmallDecimal
impl Clone for SmallDecimal
Source§fn clone(&self) -> SmallDecimal
fn clone(&self) -> SmallDecimal
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SmallDecimal
impl Debug for SmallDecimal
Source§impl PartialEq for SmallDecimal
impl PartialEq for SmallDecimal
impl Eq for SmallDecimal
impl StructuralPartialEq for SmallDecimal
Auto Trait Implementations§
impl Freeze for SmallDecimal
impl RefUnwindSafe for SmallDecimal
impl Send for SmallDecimal
impl Sync for SmallDecimal
impl Unpin for SmallDecimal
impl UnsafeUnpin for SmallDecimal
impl UnwindSafe for SmallDecimal
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> 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.