Fix intcomma()
failing with a string as input when ndigits
is not None
#52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Calling
humanize.intcomma("1", 0)
would fail with the error messageFix this by first converting the string to a
float
orint
. Always converting the string to afloat
would not work for cases likehumanize.intcomma("1")
, as this would output'1.0'
instead of the desired output'1'
.This also requires using a while loop instead of recursion, as calling this function again would now remove the thousands separator, leading to an infinite recursion. This also makes it easier to reason about IMO.
Changes proposed in this pull request: