mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 15:25:32 +00:00
Document better!
This commit is contained in:
parent
dce7c71c37
commit
2e3e5187f9
@ -25,10 +25,11 @@ use std::{
|
|||||||
pub struct PgMoney(pub i64);
|
pub struct PgMoney(pub i64);
|
||||||
|
|
||||||
impl PgMoney {
|
impl PgMoney {
|
||||||
/// Convert the money value into a [`BigDecimal`] using the correct precision
|
/// Convert the money value into a [`BigDecimal`] using the correct
|
||||||
/// defined in the PostgreSQL settings. The default precision is two.
|
/// precision defined in the PostgreSQL settings. The default precision is
|
||||||
|
/// two.
|
||||||
///
|
///
|
||||||
/// [`BigDecimal`]: ../../types/struct.BigDecimal.html
|
/// [`BigDecimal`]: crate::types::BigDecimal
|
||||||
#[cfg(feature = "bigdecimal")]
|
#[cfg(feature = "bigdecimal")]
|
||||||
pub fn to_bigdecimal(self, scale: i64) -> bigdecimal::BigDecimal {
|
pub fn to_bigdecimal(self, scale: i64) -> bigdecimal::BigDecimal {
|
||||||
let digits = num_bigint::BigInt::from(self.0);
|
let digits = num_bigint::BigInt::from(self.0);
|
||||||
@ -39,7 +40,7 @@ impl PgMoney {
|
|||||||
/// Convert the money value into a [`Decimal`] using the correct precision
|
/// Convert the money value into a [`Decimal`] using the correct precision
|
||||||
/// defined in the PostgreSQL settings. The default precision is two.
|
/// defined in the PostgreSQL settings. The default precision is two.
|
||||||
///
|
///
|
||||||
/// [`Decimal`]: ../../types/struct.BigDecimal.html
|
/// [`Decimal`]: crate::types::Decimal
|
||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
pub fn to_decimal(self, scale: u32) -> rust_decimal::Decimal {
|
pub fn to_decimal(self, scale: u32) -> rust_decimal::Decimal {
|
||||||
rust_decimal::Decimal::new(self.0, scale)
|
rust_decimal::Decimal::new(self.0, scale)
|
||||||
@ -48,7 +49,9 @@ impl PgMoney {
|
|||||||
/// Convert a [`Decimal`] value into money using the correct precision
|
/// Convert a [`Decimal`] value into money using the correct precision
|
||||||
/// defined in the PostgreSQL settings. The default precision is two.
|
/// 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")]
|
#[cfg(feature = "decimal")]
|
||||||
pub fn from_decimal(decimal: rust_decimal::Decimal, scale: u32) -> Self {
|
pub fn from_decimal(decimal: rust_decimal::Decimal, scale: u32) -> Self {
|
||||||
let cents = (decimal * rust_decimal::Decimal::new(10i64.pow(scale), 0)).round();
|
let cents = (decimal * rust_decimal::Decimal::new(10i64.pow(scale), 0)).round();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user