CodeSampleX

샘플

github.com/shopspring/decimal 1.4.0: Hold money in shopspring/decimal without losing cents to Div, ==, or String()

검증된 샘플 — golang github.com/shopspring/decimal 1.4.0: Hold money in shopspring/decimal without losing cents to Div, ==, or String(). go 1.26 · linux…

sha256:84206d243236399467879a1efbd7f91542f9c90b1d044a06e8611694204998bd

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 go 1.26 linux x64 go 1.26 go go

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
Hold money in shopspring/decimal without losing cents to Div, ==, or String()
패키지
심벌
  • decimal.NewFromString
  • decimal.NewFromFloat
  • decimal.DivisionPrecision
  • Decimal.Equal
  • Decimal.QuoRem
  • Decimal.RoundBank
  • Decimal.StringFixed
환경
go 1.26
생성일
2026-08-14T08:53:07Z

컨트랙트

  1. assert NewFromFloat(0.1).String() is "0.1" and Equal to NewFromString("0.1"), so the constructor is not where 0.1 goes wrong
  2. assert the loss happens in float64 before the constructor, including digits float64 cannot hold at all
  3. assert Go folds untyped constant 0.1+0.2 exactly, so the demo only misbehaves once the operands are variables
  4. assert Add and Mul are exact where the float64 equivalents give 7.000000000000001 and 3.3000000000000003
  5. 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)
  6. assert DivisionPrecision defaults to 16 and is a mutable global, so (1/3)*3 is 0.9999999999999999 and not 1
  7. assert Div rounds rather than truncates, so 2/3 ends in a 7, and DivRound takes the precision as an argument
  8. 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
  9. assert Equal compares values while == compares the *big.Int pointer and the scale, so two parses of "1.0" are not ==
  10. assert the zero value is a usable 0 that is Equal to decimal.Zero but not == to New(0,0)
  11. assert Cmp orders numerically and drops into slices.SortFunc as a method expression
  12. 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
  13. assert rounding cents through float64 obeys neither rule, because 1.005 falls below the half and 8.045 lands exactly on it
  14. assert String() trims trailing zeros while the exponent stays -2, and StringFixed / StringFixedBank are the money formats
  15. assert NewFromString rejects "1,005" instead of guessing a number

파일

  • csx.json
  • go.mod
  • go.sum
  • src/money.go
  • test/main.go

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous