Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

sprintf formatting with "%+.2d" #936

Closed
eregon opened this Issue · 3 comments

2 participants

@eregon
Collaborator
$ 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)

@BanzaiMan BanzaiMan was assigned
@BanzaiMan BanzaiMan closed this issue from a commit
@BanzaiMan BanzaiMan Fill 0 for negative decimals if precision is given
If precision is given for negative decimals, fill in 0's as necessary.
This fixes #936.
ba28553
@BanzaiMan BanzaiMan closed this in ba28553
@BanzaiMan
Owner

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
Collaborator

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

@eregon
Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.