🐛 Fix decimal rounding and format in WebGL rulers (#10487)

This commit is contained in:
Elena Torró 2026-06-30 10:35:03 +02:00 committed by GitHub
parent f993f203bd
commit 21f646aeee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 9 deletions

View File

@ -74,15 +74,13 @@ fn calculate_step_size(zoom: f32) -> f32 {
} }
fn format_label(value: f32) -> String { fn format_label(value: f32) -> String {
// Match `format-number` in app.main.ui.formats: round to integer if whole, // Match `format-number` in app.main.ui.formats: round to at most 2 decimals.
// else 2 decimals. Tick steps are integers in our table, so this is the // Display drops trailing zeros for free, so 123.00 -> "123",
// common path. // 123.50 -> "123.5", 123.456 -> "123.46".
let rounded = value.round(); let rounded = (value * 100.0).round() / 100.0;
if (value - rounded).abs() < 1e-3 { // Normalize -0.0 so we don't render "-0".
format!("{}", rounded as i64) let rounded = if rounded == 0.0 { 0.0 } else { rounded };
} else { format!("{rounded}")
format!("{:.2}", value)
}
} }
fn with_alpha(color: Color, alpha_fraction: f32) -> Color { fn with_alpha(color: Color, alpha_fraction: f32) -> Color {