Always display ballot weights to at least 2 decimal places

This commit is contained in:
RunasSudo 2021-06-06 00:53:52 +10:00
parent c6d8ba16dd
commit 62eac6d0a6
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 4 additions and 3 deletions

View File

@ -84,7 +84,7 @@ impl From<usize> for Rational {
}
impl From<f64> for Rational {
fn from(n: f64) -> Self {
fn from(_n: f64) -> Self {
// FIXME: This is very broken!
//return Self(RatioType::from_float(n).unwrap() * RatioType::from_integer(100000).round() / RatioType::from_integer(100000));
todo!();

View File

@ -25,6 +25,7 @@ use crate::election::{Candidate, CandidateState, CountCard, CountState, Parcel,
use wasm_bindgen::prelude::wasm_bindgen;
use std::cmp::max;
use std::collections::HashMap;
use std::ops;
@ -581,7 +582,7 @@ where
transfer_value.as_mut().unwrap().floor_mut(dps);
}
state.logger.log_literal(format!("Surplus of {} distributed at value {:.dps$}.", elected_candidate.name, transfer_value.as_ref().unwrap(), dps=opts.pp_decimals));
state.logger.log_literal(format!("Surplus of {} distributed at value {:.dps2$}.", elected_candidate.name, transfer_value.as_ref().unwrap(), dps2=max(opts.pp_decimals, 2)));
}
None => {
transfer_value = None;
@ -791,7 +792,7 @@ where
if let ExclusionMethod::SingleStage = opts.exclusion {
state.logger.log_literal(format!("Transferring {:.0} ballot papers, totalling {:.dps$} votes.", result.total_ballots, result.total_votes, dps=opts.pp_decimals));
} else {
state.logger.log_literal(format!("Transferring {:.0} ballot papers, totalling {:.dps$} votes, received at value {:.dps$}.", result.total_ballots, result.total_votes, value, dps=opts.pp_decimals));
state.logger.log_literal(format!("Transferring {:.0} ballot papers, totalling {:.dps$} votes, received at value {:.dps2$}.", result.total_ballots, result.total_votes, value, dps=opts.pp_decimals, dps2=max(opts.pp_decimals, 2)));
}
// Transfer candidate votes