Skip to content
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 formatting with "%+.2d" #936

Closed
eregon opened this Issue Aug 1, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@eregon
Copy link
Member

eregon commented Aug 1, 2013

$ ruby -e 'puts "%+.2d" % -9'
MRI JRuby
-09 -9

From the rdoc:

For numeric fields, the precision controls the number of decimal places
displayed.
[...]
Examples of precisions:

  # precision for `d', 'o', 'x' and 'b' is
  # minimum number of digits               <------>
  sprintf("%20.8d", 123)  #=> "            00000123"
  sprintf("%20.8d", -123) #=> "           -00000123"

This makes a Date test fail so it would be valuable to me if it can be fixed quickly :)
(I looked at Sprintf with jdb but got kind of lost with a width of -3)

@ghost ghost assigned BanzaiMan Sep 2, 2013

@BanzaiMan BanzaiMan closed this in ba28553 Sep 2, 2013

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Sep 2, 2013

We'd probably need specs for negative decimals with a given precision. https://github.com/rubyspec/rubyspec/blob/3edae0ad/core/string/modulo_spec.rb#L391-L397 is close, but not quite.

@eregon

This comment has been minimized.

Copy link
Member Author

eregon commented Sep 2, 2013

Great! I'll add a ruby spec for that case.

@eregon

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.