TWD 顯示改為整數(四捨五入到個位)
This commit is contained in:
@@ -139,12 +139,9 @@ fn parse_amount(s: &str) -> Option<f64> {
|
||||
}
|
||||
|
||||
fn format_twd(v: f64) -> String {
|
||||
let rounded = (v * 100.0).round() / 100.0;
|
||||
let sign = if rounded < 0.0 { "-" } else { "" };
|
||||
let abs = rounded.abs();
|
||||
let int_part = abs.trunc() as u64;
|
||||
let frac = ((abs - int_part as f64) * 100.0).round() as u64;
|
||||
let int_str = int_part.to_string();
|
||||
let rounded = v.round() as i64;
|
||||
let sign = if rounded < 0 { "-" } else { "" };
|
||||
let int_str = rounded.unsigned_abs().to_string();
|
||||
let mut with_sep = String::new();
|
||||
for (i, ch) in int_str.chars().rev().enumerate() {
|
||||
if i > 0 && i % 3 == 0 {
|
||||
@@ -153,12 +150,11 @@ fn format_twd(v: f64) -> String {
|
||||
with_sep.push(ch);
|
||||
}
|
||||
let int_sep: String = with_sep.chars().rev().collect();
|
||||
format!("{sign}{int_sep}.{frac:02}")
|
||||
format!("{sign}{int_sep}")
|
||||
}
|
||||
|
||||
fn format_twd_raw(v: f64) -> String {
|
||||
let rounded = (v * 100.0).round() / 100.0;
|
||||
format!("{rounded:.2}")
|
||||
format!("{}", v.round() as i64)
|
||||
}
|
||||
|
||||
struct App {
|
||||
|
||||
Reference in New Issue
Block a user