We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fb206a0 commit 814018fCopy full SHA for 814018f
vm/src/obj/objfloat.rs
@@ -416,8 +416,20 @@ impl PyFloat {
416
417
#[pymethod(name = "__repr__")]
418
fn repr(&self, vm: &VirtualMachine) -> String {
419
- if self.is_integer(vm) {
420
- format!("{:.1?}", self.value)
+ let value = format!("{:e}", self.value);
+ if let Some(position) = value.find('e') {
421
+ let significand = &value[..position];
422
+ let exponent = &value[position + 1..];
423
+ let exponent = exponent.parse::<i32>().unwrap();
424
+ if exponent < 16 && exponent > -5 {
425
+ if self.is_integer(vm) {
426
+ format!("{:.1?}", self.value)
427
+ } else {
428
+ self.value.to_string()
429
+ }
430
431
+ format!("{}e{:+#03}", significand, exponent)
432
433
} else {
434
self.value.to_string()
435
}
0 commit comments