Fix fractional(0) returning "0/1" instead of "0" - #351
Conversation
fractional() gated the whole-number return on `whole_number` being truthy, so 0 (where whole_number == 0) fell through to the fraction branch and rendered as "0/1". Since `numerator == 0 and denominator == 1` already uniquely identifies a whole number (including 0), drop the redundant `whole_number and`. Now fractional(0) returns "0". Added regression test cases.
|
Hi @hugovk, gentle nudge on this small fix whenever you have time. Thanks for maintaining humanize. |
|
Flagging an overlap, since I only noticed it now: @semx opened #354 a few days after this one, and it covers the same Their fix folds any whole-valued fractional part into the integer part, which handles both cases in one place, so it is the more complete change of the two. I am happy to close this in favour of #354 if that is the direction you prefer, or to add their case here if you would rather keep this one. Whichever is less work for you. |
|
Thanks for the generous framing @Sreekant13 - for the record, your PR was here first, and priority counts for something too. Either direction works for me equally: if @hugovk prefers this one as first-come, I am happy to rebase #354 down to just the whole-rounding case on top of yours; if #354 goes in as the single change, credit for spotting fractional(0) first belongs here either way. Whatever is least work for the maintainer. |
fractional(0)returns"0/1"instead of"0", even though every other whole number renders bare:The whole-number return branch was gated on
whole_numberbeing truthy, so0(wherewhole_number == 0) skipped it and fell through to the fraction branch, producing"0/1". Sincenumerator == 0 and denominator == 1already uniquely identifies a whole number (including0), thewhole_number andcheck is both redundant and wrong for0. Removing it makesfractional(0)return"0", consistent withfractional(3),fractional(2.0), etc.Fixes # (no linked issue - small self-contained bug fix)
Changes proposed in this pull request:
whole_number andguard infractional()so0is treated as a whole number and returns"0"(previously"0/1").(0, "0")and(0.0, "0")totest_fractional.