-
Notifications
You must be signed in to change notification settings - Fork 0
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
\%d()
inconsistency with Float64
#5
Comments
This should actually be raised as an issue with Format.jl.
I will look into this, thanks for the input! |
I've compared things a bit - for C/C++ formatted strings, you get garbage results if you use a double (Float64) with the I don't think I should change how Format handles the d specifier, it is consistent with Julia's Printf function, and you can use the f specifier to get integer results, for both floating point and integer input. |
I tried to understand your points, but I don't see how consistency with other languages matter. The goal should be usefulness to the end user (Julia programmer). Do you really think that giving a garbage result is a good outcome for the user? I don't think you do. Because Julia silently converts 1.0 to 1 usually, getting a sensible result from the format "%4.4d(x)" even when Then, if we give a sensible outcome, which is better, Do you really think that giving If you argued that an error should be the right outcome, then there is some merit in that argument. But, there is no valid argument for " 1" from "%4.4d(x)" with x being Float64. The outcome should be error or "0001". |
A big part of the problem, is that |
When you use a Float64 number with the
\%4.4d(x)
format, there are no leading zeros. A sample code is below.I know that using a Float64 for the
d
format descriptor is the cause of the problem, but it would be nice if the\%4.4d(x)
behaved as if it were%d4.4d(Int(x))
.Unlike most other programming languages, Julia silently converts Float's with Int's if the conversion is exact and complains if it's not:
I hope that the
d
format descriptor honors this "spirit" of Julia.The text was updated successfully, but these errors were encountered: