Skip to content

Commit

Permalink
fix integer fail in centile_bands, tests for on, above and between al…
Browse files Browse the repository at this point in the history
…l centile formats
  • Loading branch information
eatyourpeas committed Oct 22, 2024
1 parent 7b89e9c commit 81751b8
Show file tree
Hide file tree
Showing 2 changed files with 375 additions and 411 deletions.
10 changes: 6 additions & 4 deletions rcpchgrowth/centile_bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ def return_suffix(centile: float)->str:
# This function only works if the centile is received already rounded to 1 decimal place or 2 decimal places if reference is CDC and measurement method is BMI

# Note that if reference is CDC and measurement method is BMI, the centile is rounded to 2 decimal places if centile > 99.9


# centile should not be < 0 or > 100
if centile <=0:
return "below lowest centile.;"
if centile >= 100:
return "above highest centile."

suffix="th" # this is the default

final_number = centile

if isinstance(centile, float) and centile.is_integer():
final_number = int(centile) # convert to integer if it is a whole number
final_number = int(centile) # convert to integer if it is a whole number as removes the decimal point

suffix="th" # this is the default

# get the final digit
string_from_number = str(final_number)
Expand All @@ -65,7 +67,7 @@ def return_suffix(centile: float)->str:

# 11, 12, 13 are special cases as they take 'th'
# get the final 2 digits if not a decimal
if isinstance(final_number, float) and final_number.is_integer():
if isinstance(final_number, float) and final_number.is_integer() or (isinstance(final_number, int) and len(string_from_number) > 1):
final_two_digits = string_from_number[len(string_from_number)-2: len(string_from_number)]
if int(final_two_digits) > 10 and int(final_two_digits) < 14:
suffix = "th"
Expand Down
Loading

0 comments on commit 81751b8

Please sign in to comment.