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

Fix intcomma() failing with a string as input when ndigits is not None #52

Merged

Commits on Aug 25, 2022

  1. Fix intcomma() failing with a string as input when ndigits is not None

    Calling `humanize.intcomma("1", 0)` would fail with the error message
    ```
    ValueError: Unknown format code 'f' for object of type 'str'
    ```
    
    Fix this by first converting the string to a `float` or `int`. Always converting the string to a `float` would not work for cases like `humanize.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.
    Also add some new test cases covering this and a new example.
    Luflosi committed Aug 25, 2022
    Copy the full SHA
    33005e5 View commit details
    Browse the repository at this point in the history