Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Apr 14, 2022
1 parent 07e9ef6 commit 810e744
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import print_function
from __future__ import unicode_literals
from collections import namedtuple
from decimal import Decimal, getcontext, setcontext, Context
from decimal import Decimal
import sys
import re
import math
Expand Down Expand Up @@ -993,18 +993,15 @@ def _format(val, valtype, floatfmt, missingval="", has_invisible=True):
val, (_text_type, _binary_type)
)
if is_a_colored_number:
print("HIIIIII", val)
raw_val = _strip_invisible(val)
formatted_val = format(Decimal(str(raw_val)), floatfmt)
formatted_val = format(float(val), floatfmt)
return val.replace(raw_val, formatted_val)
else:
context = Context(clamp=1, prec=6)
setcontext(context)
try:
if "f" in floatfmt:
if int(Decimal(val)) == Decimal(val):
val = int(Decimal(val, context=context))
val = Decimal(str(val), context=context)
val = int(Decimal(val))
val = Decimal(str(val))
else:
val = float(val)
except (OverflowError, ValueError):
Expand Down

0 comments on commit 810e744

Please sign in to comment.