Reduce the epsilon value format to 5 decimal places

This commit is contained in:
Piv
2023-02-11 23:27:21 +10:30
parent ea6c5424ad
commit 37c95909db
2 changed files with 10 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
use std::collections::HashMap;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Serialize, Serializer};
#[derive(Debug, Deserialize)]
struct CsvMovementRule {
@@ -86,9 +86,17 @@ pub struct CsvCost {
pub account: String,
#[serde(rename = "COSTCENTRE")]
pub department: String,
#[serde(serialize_with = "round_serialize")]
pub value: f64,
}
fn round_serialize<S>(x: &f64, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
s.serialize_f64((x * 100000.).round() / 100000.)
}
pub fn move_money<R, L, O>(
rules_reader: csv::Reader<R>,
lines_reader: csv::Reader<L>,