TWD 顯示改為整數(四捨五入到個位)
This commit is contained in:
Binary file not shown.
@@ -86,10 +86,10 @@ private fun parseAmount(s: String): Double? =
|
|||||||
s.filter { it != ',' && !it.isWhitespace() }.takeIf { it.isNotEmpty() }?.toDoubleOrNull()
|
s.filter { it != ',' && !it.isWhitespace() }.takeIf { it.isNotEmpty() }?.toDoubleOrNull()
|
||||||
|
|
||||||
private fun roundHalfUp(v: Double): BigDecimal =
|
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 =
|
private fun formatTwd(v: Double): String =
|
||||||
DecimalFormat("#,##0.00").format(roundHalfUp(v))
|
DecimalFormat("#,##0").format(roundHalfUp(v))
|
||||||
|
|
||||||
private fun formatTwdRaw(v: Double): String =
|
private fun formatTwdRaw(v: Double): String =
|
||||||
roundHalfUp(v).toPlainString()
|
roundHalfUp(v).toPlainString()
|
||||||
|
|||||||
BIN
bot_rates.exe
BIN
bot_rates.exe
Binary file not shown.
BIN
bot_rates.zip
BIN
bot_rates.zip
Binary file not shown.
@@ -139,12 +139,9 @@ fn parse_amount(s: &str) -> Option<f64> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn format_twd(v: f64) -> String {
|
fn format_twd(v: f64) -> String {
|
||||||
let rounded = (v * 100.0).round() / 100.0;
|
let rounded = v.round() as i64;
|
||||||
let sign = if rounded < 0.0 { "-" } else { "" };
|
let sign = if rounded < 0 { "-" } else { "" };
|
||||||
let abs = rounded.abs();
|
let int_str = rounded.unsigned_abs().to_string();
|
||||||
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 mut with_sep = String::new();
|
let mut with_sep = String::new();
|
||||||
for (i, ch) in int_str.chars().rev().enumerate() {
|
for (i, ch) in int_str.chars().rev().enumerate() {
|
||||||
if i > 0 && i % 3 == 0 {
|
if i > 0 && i % 3 == 0 {
|
||||||
@@ -153,12 +150,11 @@ fn format_twd(v: f64) -> String {
|
|||||||
with_sep.push(ch);
|
with_sep.push(ch);
|
||||||
}
|
}
|
||||||
let int_sep: String = with_sep.chars().rev().collect();
|
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 {
|
fn format_twd_raw(v: f64) -> String {
|
||||||
let rounded = (v * 100.0).round() / 100.0;
|
format!("{}", v.round() as i64)
|
||||||
format!("{rounded:.2}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
|
|||||||
Reference in New Issue
Block a user