-
Notifications
You must be signed in to change notification settings - Fork 63
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
Format doesn't properly handle edge cases for the %f verb #85
Comments
I appreciate the issues. I need to get |
Thanks. Also, I wondered about %d too - it would be nice (for me) if it truncated to an integer, since it (and %x, %o etc.) are integer verbs. Maybe all integer verbs (%b, %c, %d, %o, %q, %x, %X, %U) could do this and format the same way they would an int? I've no idea if that's a good idea for anyone else though but I thought I'd mention it. |
While I'm sympathetic to the idea, I feel like that's a big—but also subtle—breaking change. For example, changing a function signature is a breaking change, but it's also noisy—the code won't compile. Silently truncating decimals is quiet and easy to miss until you realize you're charging a customer $3 instead of $3.14 and production is on fire. (Granted, that requires multiple failures along the way but still...) Even for v4 (a major version, so breaking changes are allowed) I'd be a little nervous making the change. I'm open to using a verb other than one that's already taken by either this package or the |
Yeah, I take your point but I figured I'd mention it. I guess I just assumed fmt integer verbs would truncate to integers here, but I'm not sure why. I also thought about maybe capitalised versions truncating to int (so %D etc.) but that wouldn't work so well with the %x/%X distinction. Oh well - thanks for your thoughts. |
#87 fix %f format issue |
Keeping this open for a bit just until I've bettered the tests. |
Not sure if this is the desired behaviour in the Go operating mode, but this test fails (gives
|
Another one (again, only in Go mode, gives
|
It looks like the above two are intentional.
|
@mpwalkerdine hi I just wanted to let you know I saw your comments and am taking a look. Sorry for the delay. |
No worries, and thanks for the great library! 😃 |
Update: I’m rewriting part of the Format code because it’s too complicated right now. That’ll fix the issues. |
I don't know if you're interested in these formatting problems or not. I promise you I'm not deliberately seeking them!
From my logs it looks as if a lot of small numbers are being formatted as 0. I can reproduce it with the value 0.01 (I use 1% often in some code) and the format string '%.10f' (which I pretty much use for all the values I print).
I've updated my number format program to show you exactly what I mean:
The current code outputs:
(The last lines show a small inconsistency with '%f' but that's less of a concern for me.)
Many thanks,
Geoff
The text was updated successfully, but these errors were encountered: