Translation QA

The numerical values in the translation are correct, but the units have been omitted: the check should be performed in two layers

in the translation, 1,234.50 becomes 1.234,50, may merely represent a change in the numeric format, or it might be incorrectly parsed as another quantity. Numer

阅读文本 / Reading text
This paper uses synthetic samples to demonstrate the processing method. The code has been verified using examples in an isolated environment; this does not guarantee effectiveness for all real files or products. Before processing important files, please retain the original copies and verify them against the boundaries and acceptance criteria specified in the text. in the translation, 1,234.50 becomes 1.234,50 , may merely represent a change in the numeric format, or it might be incorrectly parsed as another quantity. Numerical verification must first declare the input rules before comparing normalized values; currency and units should be retained as separate, independent fields. does not allow the server language to substitute for the business protocol This document covers only two explicit formats: comma as thousands separator and period as decimal separator, and period as thousands separator and comma as decimal separator. Spaces as thousands separators, negative numbers enclosed in parentheses, scientific notation, and other notations are outside the scope. When the source rules are unclear, guesses should be rejected. first validates the format, then performs the Decimal conversion import re from decimal import Decimal def amount(text, style): rules = { "comma_group": (r"-?(?:[0-9]{1,3}(?:,[0-9]{3})+|[0-9]+)(?:\.[0-9]+)?", ",", "."), "dot_group": (r"-?(?:[0-9]{1,3}(?:\.[0-9]{3})+|[0-9]+)(?:,[0-9]+)?", ".", ",") } if style not in rules: raise ValueError("unknown number convention") pattern, grouping, decimal = rules[style] if re.fullmatch(pattern, text) is None: raise ValueError("number does not match declared convention") return Decimal(text.replace(grouping, "").replace(decimal, ".")) assert amount("1,234.50", "comma_group") == amount("1.234,50", "dot_group") assert amount("-12.50", "comma_group") == Decimal("-12.50") assert (amount("12.50", "comma_group"), "USD") != (amount("12.50", "comma_group"), "EUR") for bad in ["12,34.50", "1,234.50 USD", "NaN"]: try: amount(bad, "comma_group") except ValueError: pass else: raise AssertionError("invalid number accepted") values being identical are still not sufficient This code receives the already identified amount string and does not automatically extract the amount from any document. When locating fields, the tags, currency, and source location should be preserved. A numerical match with a unit change—from kilograms to pounds, or from total price to unit price—does not constitute a valid verification. comparison result should check should not automatically perform with the same value but different currencies Has the currency symbol been altered? is by default considered equivalent to format does not conform to the declaration source region or extraction error unconditionally removes all punctuation negative sign disappears Original text and translation context automatically takes the absolute value precision reduction Whether to round according to the rules ignores all differences Decimal addresses only part of the problem using Decimal can avoid certain binary floating-point representation errors, but it cannot choose the rounding rule for you, interpret tax amounts, or perform currency conversions. Whenever you convert a numeric value, you should retain both the original and converted values, along with the rationale, in the list. The numerical values in the translation file warrant separate acceptance via OmniDoc (Product Entry) When processing quotations, reports, or technical documents, you can first organize the amount and unit check items, then cross-reference them with the translation. The numerical verification is responsible for identifying potential discrepancies, but ultimately you must return to the original text to confirm which business field it represents. Reference: Python decimal 。 - 1 -
Updated 2026-10-08