Skip to content

Commit

Permalink
Add methods BigDecimal::{into,as}_bigint_and_scale
Browse files Browse the repository at this point in the history
  • Loading branch information
akubera committed Dec 6, 2024
1 parent 9ed0395 commit 8e0735f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ use self::stdlib::str::FromStr;
use self::stdlib::string::{String, ToString};
use self::stdlib::fmt;
use self::stdlib::Vec;
use self::stdlib::borrow::Cow;

use num_bigint::{BigInt, BigUint, ParseBigIntError, Sign};
use num_integer::Integer as IntegerTrait;
Expand Down Expand Up @@ -572,6 +573,24 @@ impl BigDecimal {
(self.int_val.clone(), self.scale)
}

/// Take BigDecimal and split into `num::BigInt` of digits, and the scale
///
/// Scale is number of digits after the decimal point, can be negative.
///
pub fn into_bigint_and_scale(self) -> (BigInt, i64) {
(self.int_val, self.scale)
}


/// Return digits as borrowed Cow of integer digits, and its scale
///
/// Scale is number of digits after the decimal point, can be negative.
///
pub fn as_bigint_and_scale(&self) -> (Cow<'_, BigInt>, i64) {
let cow_int = Cow::Borrowed(&self.int_val);
(cow_int, self.scale)
}

/// Convert into the internal big integer value and an exponent. Note that a positive
/// exponent indicates a negative power of 10.
///
Expand Down

0 comments on commit 8e0735f

Please sign in to comment.