-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
sprintf: fix number formatting quirks wrt float/int #4610
Comments
I'd like to take a stab at completing this! Please assign it to me. |
Thanks! LMK if you need assistance or if something is unclear or if you'd like to discuss some approach... 😃 |
Question: @srenatus Let's say I set the format to %.3f in the example you've shown above. Would this be the expected output?
OR would you prefer to see the exact same with the int value?
|
Hmm I think I'd go with |
* Increase IOPS * Remove policy-path until open-policy-agent/opa#4610 has been fixed
Fixes #4610. Signed-off-by: Damien Burks <damien@damienjburks.com>
feat: add this back as open-policy-agent/opa#4610 has been fixed
Yeah that other issue is what to watch now. We could reopen this one, anyways, you're right. |
Is there any update on this? Just got bit by this recently. |
Nope, no work has happened on this since, AFAICT 😓 |
This should output
"13"
. Using%v
is a workaround, but won't allow us to control the number of digits after the dot, like%.3f
would allow.The problem is this code: https://github.com/open-policy-agent/opa/blob/v0.39.0/topdown/strings.go#L427-L436
☝️ We're trying to find the best format of the arg to pass along to the golang stdlib Printf function. The heuristic breaks down when you try to format a number that could be an int or a float internally.
Here's another example:
The desired output would be
[ "1", "1.100000"]
.💭 One approach would be to examine the format string, and prepare the number argument accordingly: If the n-th format specifier is of the float-y type, make the n-th arg a float; if it's int-y, make it an int.
The text was updated successfully, but these errors were encountered: