@@ -91,8 +91,10 @@ def standardize(
9191 scientific : bool = True ,
9292 engineering : bool = True ,
9393 pep515 : bool = True ,
94+ dec_number : Decimal | None = None ,
9495 ) -> str :
95- dec_number = Decimal (original_string )
96+ if dec_number is None :
97+ dec_number = Decimal (original_string )
9698 dec_tuple = dec_number .as_tuple ()
9799 # float64 guarantees only 15 significant digits; cap suggestions
98100 # to avoid implying false precision.
@@ -795,12 +797,14 @@ def _check_bad_number_notation( # pylint: disable=too-many-locals
795797 ) -> None :
796798
797799 has_exponent = "e" in string or "E" in string
798- value = float (string .replace ("_" , "" ))
800+ clean = string .replace ("_" , "" )
801+ value = float (clean )
799802 engineering = self .all_number_notation_allowed or self .strict_engineering
800803 scientific = self .all_number_notation_allowed or self .strict_scientific
801804 pep515 = self .all_number_notation_allowed or self .strict_underscore
802805
803- sig_figs = len (Decimal (string .replace ("_" , "" )).as_tuple ().digits )
806+ dec_number = Decimal (clean )
807+ sig_figs = len (dec_number .as_tuple ().digits )
804808
805809 def add_bad_notation_message (reason : str ) -> None :
806810 suggestion = NumberFormatterHelper .standardize (
@@ -809,6 +813,7 @@ def add_bad_notation_message(reason: str) -> None:
809813 scientific ,
810814 engineering ,
811815 pep515 ,
816+ dec_number ,
812817 )
813818 if suggestion == string .lower ():
814819 return
0 commit comments