1
1
use muropeptide:: { Muropeptide , POLYMERIZER } ;
2
2
use polychem:: { ChargedParticle , Massive } ;
3
+ use rust_decimal:: Decimal ;
3
4
use smithereens:: Dissociable ;
4
5
use std:: fmt:: Write ;
5
6
use wasm_bindgen:: prelude:: * ;
@@ -35,7 +36,7 @@ impl Peptidoglycan {
35
36
#[ must_use]
36
37
pub fn monoisotopic_mass ( & self ) -> String {
37
38
let mass = self . 0 . monoisotopic_mass ( ) ;
38
- format ! ( "{ mass:.6}" )
39
+ decimal_round_workaround ( mass, 6 )
39
40
}
40
41
41
42
#[ must_use]
@@ -53,8 +54,15 @@ impl Peptidoglycan {
53
54
let mut csv = String :: new ( ) ;
54
55
writeln ! ( & mut csv, "Structure,Ion M/Z" ) . unwrap ( ) ;
55
56
for ( structure, mz) in fragments {
56
- writeln ! ( & mut csv, r#""{structure}",{mz:.6}"# ) . unwrap ( ) ;
57
+ let mz = decimal_round_workaround ( mz, 6 ) ;
58
+ writeln ! ( & mut csv, r#""{structure}",{mz}"# ) . unwrap ( ) ;
57
59
}
58
60
csv
59
61
}
60
62
}
63
+
64
+ // FIXME: Really this should be fixed in `rust_decimal`...
65
+ fn decimal_round_workaround ( value : impl Into < Decimal > , decimal_points : u32 ) -> String {
66
+ let value = value. into ( ) . round_dp ( decimal_points) ;
67
+ format ! ( "{value}" )
68
+ }
0 commit comments