Skip to content

Commit aebbf97

Browse files
committed
Add example to Decimal::new / Decimal256::new using the new Uint256::new
1 parent 0e66e9d commit aebbf97

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/std/src/math/decimal.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ impl Decimal {
4343

4444
/// Creates a Decimal(value)
4545
/// This is equivalent to `Decimal::from_atomics(value, 18)` but usable in a const context.
46+
///
47+
/// ## Examples
48+
///
49+
/// ```
50+
/// # use cosmwasm_std::{Uint128, Decimal};
51+
/// let atoms = Uint128::new(141_183_460_469_231_731_687_303_715_884_105_727_125);
52+
/// let value = Decimal::new(atoms);
53+
/// assert_eq!(value.to_string(), "141183460469231731687.303715884105727125");
54+
/// ```
4655
pub const fn new(value: Uint128) -> Self {
4756
Self(value)
4857
}

packages/std/src/math/decimal256.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ impl Decimal256 {
4848

4949
/// Creates a Decimal256 from Uint256
5050
/// This is equivalent to `Decimal256::from_atomics(value, 18)` but usable in a const context.
51+
///
52+
/// ## Examples
53+
///
54+
/// ```
55+
/// # use cosmwasm_std::{Uint256, Decimal256};
56+
/// let atoms = Uint256::new(141_183_460_469_231_731_687_303_715_884_105_727_125);
57+
/// let value = Decimal256::new(atoms);
58+
/// assert_eq!(value.to_string(), "141183460469231731687.303715884105727125");
59+
/// ```
5160
pub const fn new(value: Uint256) -> Self {
5261
Self(value)
5362
}

0 commit comments

Comments
 (0)