Skip to content

Change repr(float) if float(int(f)) == f #104

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

Merged
merged 4 commits into from Sep 30, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
target only integer-like floats
  • Loading branch information
Tim-St committed Sep 29, 2019
commit 5057b16e6b5ec25829d6dd57940d203f5ea9dadc
8 changes: 3 additions & 5 deletions py/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ func FloatNew(metatype *Type, args Tuple, kwargs StringDict) (Object, error) {
}

func (a Float) M__str__() (Object, error) {
s := fmt.Sprintf("%g", a)
if idx := strings.IndexByte(s, '.'); idx == -1 {
// Sprintf implementation could change, so it's safer to check for '.'
s += ".0"
if i := int64(a); Float(i) == a {
return String(fmt.Sprintf("%d.0", i)), nil
}
return String(s), nil
return String(fmt.Sprintf("%g", a)), nil
}

func (a Float) M__repr__() (Object, error) {
Expand Down