Sample
github.com/shopspring/decimal 1.4.0: Hold money in shopspring/decimal without losing cents to Div, ==, or String()
Verified sample for golang github.com/shopspring/decimal 1.4.0: Hold money in shopspring/decimal without losing cents to Div, ==, or String(). The contract…
sha256:84206d243236399467879a1efbd7f91542f9c90b1d044a06e8611694204998bd
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
go 1.26 linux x64 go 1.26 go go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-14 |
| go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-18 |
Case
HOW- Goal
- Hold money in shopspring/decimal without losing cents to Div, ==, or String()
- Packages
- Symbols
-
- decimal.NewFromString
- decimal.NewFromFloat
- decimal.DivisionPrecision
- Decimal.Equal
- Decimal.QuoRem
- Decimal.RoundBank
- Decimal.StringFixed
- Environment
- go 1.26
- Created
- 2026-08-14T08:53:07Z
Contract
- assert NewFromFloat(0.1).String() is "0.1" and Equal to NewFromString("0.1"), so the constructor is not where 0.1 goes wrong
- assert the loss happens in float64 before the constructor, including digits float64 cannot hold at all
- assert Go folds untyped constant 0.1+0.2 exactly, so the demo only misbehaves once the operands are variables
- assert Add and Mul are exact where the float64 equivalents give 7.000000000000001 and 3.3000000000000003
- assert Mul adds the exponents of its operands while Add and Sub keep the finer of the two, and the Sum identity decimal.Zero is New(0,1) rather than New(0,0)
- assert DivisionPrecision defaults to 16 and is a mutable global, so (1/3)*3 is 0.9999999999999999 and not 1
- assert Div rounds rather than truncates, so 2/3 ends in a 7, and DivRound takes the precision as an argument
- assert QuoRem returns the exact remainder and splitting 10.00 three ways adds back up to 10.00, while a total finer than the split scale pays out a cent more
- assert Equal compares values while == compares the *big.Int pointer and the scale, so two parses of "1.0" are not ==
- assert the zero value is a usable 0 that is Equal to decimal.Zero but not == to New(0,0)
- assert Cmp orders numerically and drops into slices.SortFunc as a method expression
- assert Round is half away from zero and RoundBank is half to even, that they agree wherever the digit ahead of the half is odd, and that the disagreement moves a four-line invoice total by two cents
- assert rounding cents through float64 obeys neither rule, because 1.005 falls below the half and 8.045 lands exactly on it
- assert String() trims trailing zeros while the exponent stays -2, and StringFixed / StringFixedBank are the money formats
- assert NewFromString rejects "1,005" instead of guessing a number
Files
- csx.json
- go.mod
- go.sum
- src/money.go
- test/main.go