Repository navigation
Encode decimal_string values in fixed-point notation - #2002
Open
zacchua-stripe wants to merge 1 commit into
Open
zacchua-stripe wants to merge 1 commit into
zacchua-stripe wants to merge 1 commit into
Conversation
_encode_decimal used str(), which switches to exponent notation for
small and large values: str(0.00001) is "1e-05", str(1e16) is "1e+16",
and str(Decimal("0.0000001")) is "1E-7". The V2 API rejects decimal
strings in exponent notation.
Format finite Decimals with format(dec, "f"), and convert finite floats
through Decimal(repr(value)) first so they keep their shortest
round-trip digits. Values that str() already wrote in fixed-point,
non-finite values, and ints are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Committed-By-Agent: claude
zacchua-stripe
marked this pull request as ready for review
November 23, 2026 20:32
zacchua-stripe
requested review from
jar-stripe and
mark-kogan-stripe
and removed request for
a team
November 23, 2026 20:32
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
V2
decimal_stringfields are sent as strings, and_encode_decimalconverts aDecimalorfloatto that string withstr().str()switches to exponent notation for small and large values:str(0.00001)is"1e-05",str(1e16)is"1e+16", andstr(Decimal("0.0000001"))is"1E-7".The V2 API only accepts decimal strings in fixed-point notation, so it rejects these values. This affects the
Decimaltype the SDK asks users to pass, not just floats.What?
_encode_decimalformats finiteDecimalvalues withformat(value, "f"), and converts finite floats throughDecimal(repr(value))first so they keep their shortest round-trip digits (0.1stays"0.1")str()already writes in fixed-point notation, non-finite values, and ints are unchangeddecimal_stringrequest params,Decimalvalues in JSON request bodies, andStripeObjectJSON output, which all go through_encode_decimalDecimalandfloatvalues, unchanged values, lists, and a JSON request bodySee Also
https://go/j/RUN_DEVSDK-3739
Configuration
skip-changefile: This PR is not a user-facing change, so there's no changefile.