summaryrefslogtreecommitdiff
path: root/src/geom
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-04 21:29:15 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-04 21:29:15 +0100
commit2e77b1c836220766398e379ae0157736fb448874 (patch)
tree70fc7d28f44193f26d880b5315ce55ed951af73c /src/geom
parent77c06ebc24ab3a43dc2268763ff8f10963f875b4 (diff)
Better value representations, type function 🌐
Diffstat (limited to 'src/geom')
-rw-r--r--src/geom/length.rs6
-rw-r--r--src/geom/relative.rs2
2 files changed, 4 insertions, 4 deletions
diff --git a/src/geom/length.rs b/src/geom/length.rs
index 0e445153..23650e89 100644
--- a/src/geom/length.rs
+++ b/src/geom/length.rs
@@ -90,7 +90,7 @@ impl Display for Length {
} else {
(self.to_cm(), Unit::Cm)
};
- write!(f, "{:.2}{}", val, unit)
+ write!(f, "{}{}", (val * 100.0).round() / 100.0, unit)
}
}
@@ -214,8 +214,8 @@ mod tests {
#[test]
fn test_length_formatting() {
- assert_eq!(Length::pt(-28.34).to_string(), "-1.00cm".to_string());
- assert_eq!(Length::pt(23.0).to_string(), "23.00pt".to_string());
+ assert_eq!(Length::pt(-28.34).to_string(), "-1cm".to_string());
+ assert_eq!(Length::pt(23.0).to_string(), "23pt".to_string());
assert_eq!(Length::cm(12.728).to_string(), "12.73cm".to_string());
}
}
diff --git a/src/geom/relative.rs b/src/geom/relative.rs
index ce473e3d..fdd1f9bb 100644
--- a/src/geom/relative.rs
+++ b/src/geom/relative.rs
@@ -32,7 +32,7 @@ impl Relative {
impl Display for Relative {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- write!(f, "{:.2}%", self.0)
+ write!(f, "{}%", (self.0 * 10000.0).round() / 100.0)
}
}