Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unicode minus signs in HTML output #734

Merged
merged 3 commits into from
Oct 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ pub fn short(n: f64) -> String {
fn signed_short(n: f64) -> String {
let n_abs = n.abs();

let sign = if n >= 0.0 { '+' } else { '\u{2212}' };
if n_abs < 10.0 {
format!("{:+.4}", n)
format!("{}{:.4}", sign, n_abs)
} else if n_abs < 100.0 {
format!("{:+.3}", n)
format!("{}{:.3}", sign, n_abs)
} else if n_abs < 1000.0 {
format!("{:+.2}", n)
format!("{}{:.2}", sign, n_abs)
} else if n_abs < 10000.0 {
format!("{:+.1}", n)
format!("{}{:.1}", sign, n_abs)
} else {
format!("{:+.0}", n)
format!("{}{:.0}", sign, n_abs)
}
}

Expand Down Expand Up @@ -124,7 +125,7 @@ mod test {
while float > -999_999.9 {
let string = signed_short(float);
println!("{}", string);
assert!(string.len() <= 7);
assert!(string.chars().count() <= 7);
float *= 2.0;
}
}
Expand Down