Merge pull request #1384 from tsvankay/float_repr

Fix __repr__ return value for -0.0
This commit is contained in:
Windel Bouwman
2019-09-17 19:54:53 +02:00
committed by GitHub
2 changed files with 2 additions and 1 deletions

View File

@@ -198,6 +198,7 @@ assert_raises(ValueError, float('nan').as_integer_ratio)
assert str(1.0) == '1.0'
assert str(0.0) == '0.0'
assert str(-0.0) == '-0.0'
assert str(1.123456789) == '1.123456789'
# Test special case for lexer, float starts with a dot:

View File

@@ -411,7 +411,7 @@ impl PyFloat {
#[pymethod(name = "__repr__")]
fn repr(&self, vm: &VirtualMachine) -> String {
if self.is_integer(vm) {
format!("{:.1}", self.value)
format!("{:.1?}", self.value)
} else {
self.value.to_string()
}