You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use serde::{Serialize, Deserialize};
use rust_decimal::prelude::*;
use std::collections::HashSet;
#[derive(Deserialize, Serialize)]
pub struct Foo {
value: Decimal,
}
fn main() {
let s = Foo {
value: Decimal::new(-1, 3).round_dp(0),
};
let _ser = bincode::serialize(&s).unwrap();
let _des: Foo = bincode::deserialize(&ser).unwrap();
}
[dependencies]
rust_decimal_macros = { version = "1.12.2" }
rust_decimal= { version = "1.12.2", features=["serde-str"] }
bincode = "1.3.1"
serde = { version = "1.0.117", features = [ "derive" ] }
Output
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom("invalid value: string \"-\", expected a Decimal type representing a fixed-point number")', src/main.rs:17:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I believe any negative decimal < 0 with round_dp(0) panics.
The text was updated successfully, but these errors were encountered:
Thanks for this. Was perplexing me for a bit but discovered it was primarily to do with numbers being rounded towards 0 whilst retaining negativity. I'll push up a fix.
main.rs
Output
I believe any negative decimal < 0 with
round_dp(0)
panics.The text was updated successfully, but these errors were encountered: