Skip to content

Commit

Permalink
fix a bug where units would not be printed for zero exponent
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdsharpe committed Dec 21, 2023
1 parent c1386ba commit 612183d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions aerosandbox/tools/string_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ def eng_string(
exp3 = exp - (exp % 3)
x3 = x / (10 ** exp3)

if exp3 == 0:
suffix = ''
elif si and exp3 >= -24 and exp3 <= 24:
suffix = 'yzafpnμm kMGTPEZY'[(exp3 + 24) // 3]
if si and exp3 >= -24 and exp3 <= 24:
if exp3 == 0:
suffix = ""
else:
suffix = 'yzafpnμm kMGTPEZY'[(exp3 + 24) // 3]

if add_space_after_number is None:
add_space_after_number = (unit != "")
Expand All @@ -80,7 +81,7 @@ def eng_string(
else:
suffix = suffix + unit

return ('%s' + format + '%s') % (sign, x3, suffix)
return f"{sign}{format % x3}{suffix}"


def latex_sci_notation_string(
Expand Down

0 comments on commit 612183d

Please sign in to comment.