diff --git a/BotRates.app/Contents/MacOS/BotRates b/BotRates.app/Contents/MacOS/BotRates index 77487c8..db32bf2 100755 Binary files a/BotRates.app/Contents/MacOS/BotRates and b/BotRates.app/Contents/MacOS/BotRates differ diff --git a/android/app/src/main/java/tw/local/botrates/MainActivity.kt b/android/app/src/main/java/tw/local/botrates/MainActivity.kt index 431fd8f..263ad36 100644 --- a/android/app/src/main/java/tw/local/botrates/MainActivity.kt +++ b/android/app/src/main/java/tw/local/botrates/MainActivity.kt @@ -86,10 +86,10 @@ private fun parseAmount(s: String): Double? = s.filter { it != ',' && !it.isWhitespace() }.takeIf { it.isNotEmpty() }?.toDoubleOrNull() private fun roundHalfUp(v: Double): BigDecimal = - BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_UP) + BigDecimal.valueOf(v).setScale(0, RoundingMode.HALF_UP) private fun formatTwd(v: Double): String = - DecimalFormat("#,##0.00").format(roundHalfUp(v)) + DecimalFormat("#,##0").format(roundHalfUp(v)) private fun formatTwdRaw(v: Double): String = roundHalfUp(v).toPlainString() diff --git a/bot_rates.exe b/bot_rates.exe index f0b8c32..49113c7 100755 Binary files a/bot_rates.exe and b/bot_rates.exe differ diff --git a/bot_rates.zip b/bot_rates.zip index 93af785..079b6ce 100644 Binary files a/bot_rates.zip and b/bot_rates.zip differ diff --git a/bot_rates_rs/src/main.rs b/bot_rates_rs/src/main.rs index 88cbd33..602a68f 100644 --- a/bot_rates_rs/src/main.rs +++ b/bot_rates_rs/src/main.rs @@ -139,12 +139,9 @@ fn parse_amount(s: &str) -> Option { } 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 {