Update monetary limits for numeric precision in BaseWorker and UserCharacterWorker: Changed maximum absolute values from numeric(10,2) to numeric(14,2) to accommodate larger monetary amounts. Adjusted related comments and clamping logic to reflect the new limits, ensuring accurate handling of monetary values.
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 2m19s

This commit is contained in:
Torsten Schulz (local)
2026-05-06 11:04:45 +02:00
parent 43eb6ed0ab
commit 8509a7e171
6 changed files with 103 additions and 13 deletions

View File

@@ -158,8 +158,8 @@ impl BaseWorker {
)));
}
// We must ensure the resulting money fits in numeric(10,2).
// numeric(10,2) max absolute value is < 10^8 (100_000_000) before rounding.
// We must ensure the resulting money fits in numeric(14,2).
// numeric(14,2) max absolute value is < 10^12 before rounding.
// Fetch current money for the user and clamp the delta if needed.
conn.prepare("get_money_for_clamp", QUERY_GET_MONEY)?;
let rows = conn.execute("get_money_for_clamp", &[&falukant_user_id])?;
@@ -173,13 +173,13 @@ impl BaseWorker {
// compute tentative result
let tentative = current_money + money_change;
// numeric(10,2) allows values with absolute < 10^8 (100_000_000)
const MAX_ABS: f64 = 100_000_000.0 - 0.01; // leave room for scale
// numeric(14,2) allows values with absolute < 10^12
const MAX_ABS: f64 = 1_000_000_000_000.0 - 0.01; // leave room for scale
let adjusted_money_change = if tentative >= MAX_ABS {
let clipped = MAX_ABS - current_money;
eprintln!(
"[BaseWorker] Clamping money_change: tentative {} exceeds numeric(10,2) max, clipping to {}",
"[BaseWorker] Clamping money_change: tentative {} exceeds numeric(14,2) max, clipping to {}",
tentative, clipped
);
clipped

View File

@@ -706,7 +706,7 @@ impl UserCharacterWorker {
let clamped = if !new_amount.is_finite() {
1000.0
} else {
const MAX_ABS: f64 = 99_999_999.99;
const MAX_ABS: f64 = 999_999_999_999.99;
new_amount.clamp(-MAX_ABS, MAX_ABS)
};
let money_str = format!("{:.2}", clamped);