Reduce the epsilon value format to 5 decimal places
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize, Serializer};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct CsvMovementRule {
|
struct CsvMovementRule {
|
||||||
@@ -86,9 +86,17 @@ pub struct CsvCost {
|
|||||||
pub account: String,
|
pub account: String,
|
||||||
#[serde(rename = "COSTCENTRE")]
|
#[serde(rename = "COSTCENTRE")]
|
||||||
pub department: String,
|
pub department: String,
|
||||||
|
#[serde(serialize_with = "round_serialize")]
|
||||||
pub value: f64,
|
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>(
|
pub fn move_money<R, L, O>(
|
||||||
rules_reader: csv::Reader<R>,
|
rules_reader: csv::Reader<R>,
|
||||||
lines_reader: csv::Reader<L>,
|
lines_reader: csv::Reader<L>,
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ where
|
|||||||
for cost in results {
|
for cost in results {
|
||||||
for department in cost.summed_department_costs {
|
for department in cost.summed_department_costs {
|
||||||
// Any consumers should assume missing cc/account value was 0 (we already ignore overhead, as they all 0 out)
|
// Any consumers should assume missing cc/account value was 0 (we already ignore overhead, as they all 0 out)
|
||||||
if department.value != 0. {
|
if department.value > 0.00001 || department.value < -0.00001 {
|
||||||
output.serialize(CsvCost {
|
output.serialize(CsvCost {
|
||||||
account: cost.account.clone(),
|
account: cost.account.clone(),
|
||||||
department: department.department,
|
department: department.department,
|
||||||
|
|||||||
Reference in New Issue
Block a user