Skip to content

Commit

Permalink
Document better!
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn authored and abonander committed Jul 9, 2020
1 parent dce7c71 commit 2e3e518
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sqlx-core/src/postgres/types/money.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ use std::{
pub struct PgMoney(pub i64);

impl PgMoney {
/// Convert the money value into a [`BigDecimal`] using the correct precision
/// defined in the PostgreSQL settings. The default precision is two.
/// Convert the money value into a [`BigDecimal`] using the correct
/// precision defined in the PostgreSQL settings. The default precision is
/// two.
///
/// [`BigDecimal`]: ../../types/struct.BigDecimal.html
/// [`BigDecimal`]: crate::types::BigDecimal
#[cfg(feature = "bigdecimal")]
pub fn to_bigdecimal(self, scale: i64) -> bigdecimal::BigDecimal {
let digits = num_bigint::BigInt::from(self.0);
Expand All @@ -39,7 +40,7 @@ impl PgMoney {
/// Convert the money value into a [`Decimal`] using the correct precision
/// defined in the PostgreSQL settings. The default precision is two.
///
/// [`Decimal`]: ../../types/struct.BigDecimal.html
/// [`Decimal`]: crate::types::Decimal
#[cfg(feature = "decimal")]
pub fn to_decimal(self, scale: u32) -> rust_decimal::Decimal {
rust_decimal::Decimal::new(self.0, scale)
Expand All @@ -48,7 +49,9 @@ impl PgMoney {
/// Convert a [`Decimal`] value into money using the correct precision
/// defined in the PostgreSQL settings. The default precision is two.
///
/// [`Decimal`]: ../../types/struct.BigDecimal.html
/// Conversion may involve a loss of precision.
///
/// [`Decimal`]: crate::types::Decimal
#[cfg(feature = "decimal")]
pub fn from_decimal(decimal: rust_decimal::Decimal, scale: u32) -> Self {
let cents = (decimal * rust_decimal::Decimal::new(10i64.pow(scale), 0)).round();
Expand Down

0 comments on commit 2e3e518

Please sign in to comment.