@@ -1099,7 +1099,7 @@ def parse_decimal(
1099
1099
raise NumberFormatError (f"{ string !r} is not a valid decimal number" ) from exc
1100
1100
if strict and group_symbol in string :
1101
1101
proper = format_decimal (parsed , locale = locale , decimal_quantization = False , numbering_system = numbering_system )
1102
- if string != proper and string . rstrip ( '0' ) != ( proper + decimal_symbol ):
1102
+ if string != proper and proper != _remove_trailing_zeros_after_decimal ( string , decimal_symbol ):
1103
1103
try :
1104
1104
parsed_alt = decimal .Decimal (string .replace (decimal_symbol , '' )
1105
1105
.replace (group_symbol , '.' ))
@@ -1131,6 +1131,39 @@ def parse_decimal(
1131
1131
return parsed
1132
1132
1133
1133
1134
+ def _remove_trailing_zeros_after_decimal (string : str , decimal_symbol : str ) -> str :
1135
+ """
1136
+ Remove trailing zeros from the decimal part of a numeric string.
1137
+
1138
+ This function takes a string representing a numeric value and a decimal symbol.
1139
+ It removes any trailing zeros that appear after the decimal symbol in the number.
1140
+ If the decimal part becomes empty after removing trailing zeros, the decimal symbol
1141
+ is also removed. If the string does not contain the decimal symbol, it is returned unchanged.
1142
+
1143
+ :param string: The numeric string from which to remove trailing zeros.
1144
+ :type string: str
1145
+ :param decimal_symbol: The symbol used to denote the decimal point.
1146
+ :type decimal_symbol: str
1147
+ :return: The numeric string with trailing zeros removed from its decimal part.
1148
+ :rtype: str
1149
+
1150
+ Example:
1151
+ >>> _remove_trailing_zeros_after_decimal("123.4500", ".")
1152
+ '123.45'
1153
+ >>> _remove_trailing_zeros_after_decimal("100.000", ".")
1154
+ '100'
1155
+ >>> _remove_trailing_zeros_after_decimal("100", ".")
1156
+ '100'
1157
+ """
1158
+ integer_part , _ , decimal_part = string .partition (decimal_symbol )
1159
+
1160
+ if decimal_part :
1161
+ stripped_part = decimal_part .rstrip ("0" )
1162
+ return integer_part + (decimal_symbol + stripped_part if stripped_part else "" )
1163
+
1164
+ return string
1165
+
1166
+
1134
1167
PREFIX_END = r'[^0-9@#.,]'
1135
1168
NUMBER_TOKEN = r'[0-9@#.,E+]'
1136
1169
0 commit comments