{"id":13412839,"url":"https://github.com/govalues/decimal","last_synced_at":"2026-01-20T03:05:05.893Z","repository":{"id":142257628,"uuid":"612754668","full_name":"govalues/decimal","owner":"govalues","description":"Immutable floating-point decimals for Go","archived":false,"fork":false,"pushed_at":"2024-08-29T18:33:48.000Z","size":184,"stargazers_count":60,"open_issues_count":2,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-29T19:45:17.723Z","etag":null,"topics":["ansi-x3-274","decimal","financial","floating-point","general-decimal-arithmetic","go","golang","money"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/govalues/decimal#section-documentation","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/govalues.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-11T21:52:01.000Z","updated_at":"2024-08-29T18:33:04.000Z","dependencies_parsed_at":"2023-10-01T18:36:56.453Z","dependency_job_id":"c55852ea-9912-4993-8ca7-609551ad59e1","html_url":"https://github.com/govalues/decimal","commit_stats":null,"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/govalues/decimal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/govalues%2Fdecimal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/govalues%2Fdecimal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/govalues%2Fdecimal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/govalues%2Fdecimal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/govalues","download_url":"https://codeload.github.com/govalues/decimal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/govalues%2Fdecimal/sbom","scorecard":{"id":442362,"data":{"date":"2025-08-11","repo":{"name":"github.com/govalues/decimal","commit":"377e9df6035e8b27bc4a31d1af6e23e29ca4adad"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.6,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/14 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":2,"reason":"dependency not pinned by hash detected -- score normalized to 2","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/govalues/decimal/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/govalues/decimal/go.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/govalues/decimal/go.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/govalues/decimal/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/govalues/decimal/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:54: update your workflow using https://app.stepsecurity.io/secureworkflow/govalues/decimal/go.yml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   1 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":10,"reason":"project is fuzzed","details":["Info: GoBuiltInFuzzer integration found: decimal_test.go:6320","Info: GoBuiltInFuzzer integration found: decimal_test.go:6352","Info: GoBuiltInFuzzer integration found: decimal_test.go:6365","Info: GoBuiltInFuzzer integration found: decimal_test.go:6395","Info: GoBuiltInFuzzer integration found: decimal_test.go:6427","Info: GoBuiltInFuzzer integration found: decimal_test.go:6465","Info: GoBuiltInFuzzer integration found: decimal_test.go:6503","Info: GoBuiltInFuzzer integration found: decimal_test.go:6541","Info: GoBuiltInFuzzer integration found: decimal_test.go:6576","Info: GoBuiltInFuzzer integration found: decimal_test.go:6617","Info: GoBuiltInFuzzer integration found: decimal_test.go:6656","Info: GoBuiltInFuzzer integration found: decimal_test.go:6704","Info: GoBuiltInFuzzer integration found: decimal_test.go:6746","Info: GoBuiltInFuzzer integration found: decimal_test.go:6787","Info: GoBuiltInFuzzer integration found: decimal_test.go:6835","Info: GoBuiltInFuzzer integration found: decimal_test.go:6877","Info: GoBuiltInFuzzer integration found: decimal_test.go:6918","Info: GoBuiltInFuzzer integration found: decimal_test.go:6959","Info: GoBuiltInFuzzer integration found: decimal_test.go:6998","Info: GoBuiltInFuzzer integration found: decimal_test.go:7039","Info: GoBuiltInFuzzer integration found: decimal_test.go:7087","Info: GoBuiltInFuzzer integration found: decimal_test.go:7123","Info: GoBuiltInFuzzer integration found: decimal_test.go:7159","Info: GoBuiltInFuzzer integration found: decimal_test.go:7193","Info: GoBuiltInFuzzer integration found: decimal_test.go:7233","Info: GoBuiltInFuzzer integration found: decimal_test.go:7268","Info: GoBuiltInFuzzer integration found: decimal_test.go:7305","Info: GoBuiltInFuzzer integration found: decimal_test.go:7346","Info: GoBuiltInFuzzer integration found: decimal_test.go:7408","Info: GoBuiltInFuzzer integration found: decimal_test.go:7445","Info: GoBuiltInFuzzer integration found: decimal_test.go:7477","Info: GoBuiltInFuzzer integration found: decimal_test.go:7508"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T05:51:11.597Z","repository_id":142257628,"created_at":"2025-08-19T05:51:11.598Z","updated_at":"2025-08-19T05:51:11.598Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28594958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T02:08:49.799Z","status":"ssl_error","status_checked_at":"2026-01-20T02:08:44.148Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-x3-274","decimal","financial","floating-point","general-decimal-arithmetic","go","golang","money"],"created_at":"2024-07-30T20:01:29.896Z","updated_at":"2026-01-20T03:05:05.874Z","avatar_url":"https://github.com/govalues.png","language":"Go","funding_links":[],"categories":["Financial","金融"],"sub_categories":["Search and Analytic Databases","检索及分析资料库"],"readme":"# decimal\n\n[![githubb]][github]\n[![codecovb]][codecov]\n[![goreportb]][goreport]\n[![godocb]][godoc]\n[![licenseb]][license]\n[![versionb]][version]\n[![awesomeb]][awesome]\n\nPackage decimal implements correctly rounded decimal floating-point numbers for Go.\nThis package is designed specifically for use in transactional financial systems.\n\n## Key Features\n\n- **BSON, JSON, XML, SQL** - Implements the necessary interfaces for direct compatibility\n  with the [mongo-driver/bson], [encoding/json], [encoding/xml], and [database/sql] packages.\n- **No Heap Allocations** - Optimized to avoid heap allocations,\n  preventing garbage collector impact during arithmetic operations.\n- **Correct Rounding** - For all methods, the result is the one that would\n  be obtained if the true mathematical value were rounded to 19 digits of\n  precision using the [half-to-even] rounding (a.k.a. \"banker's rounding\").\n- **No Panics** - All methods are panic-free, returning errors instead of crashing\n  your application in cases such as overflow or division by zero.\n- **Immutability** - Once set, a decimal remains constant,\n  ensuring safe concurrent access across goroutines.\n- **Simple String Representation** - Decimals are represented in a straightforward\n  format avoiding the complexities of scientific or engineering notations.\n- **Rigorous Testing** - All methods are cross-validated against\n  the [cockroachdb/apd] and [shopspring/decimal] packages through extensive [fuzz testing].\n\n## Getting Started\n\n### Installation\n\nTo add the decimal package to your Go workspace:\n\n```bash\ngo get github.com/govalues/decimal\n```\n\n### Basic Usage\n\nCreate decimal values using one of the constructors.\nAfter creating a decimal, you can perform various operations as shown below:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/govalues/decimal\"\n)\n\nfunc main() {\n    // Constructors\n    d, _ := decimal.New(8, 0)               // d = 8\n    e, _ := decimal.Parse(\"12.5\")           // e = 12.5\n    f, _ := decimal.NewFromFloat64(2.567)   // f = 2.567\n    g, _ := decimal.NewFromInt64(7, 896, 3) // g = 7.896\n\n    // Arithmetic operations\n    fmt.Println(d.Add(e))              // 8 + 12.5\n    fmt.Println(d.Sub(e))              // 8 - 12.5\n    fmt.Println(d.SubAbs(e))           // abs(8 - 12.5)\n\n    fmt.Println(d.Mul(e))              // 8 * 12.5\n    fmt.Println(d.AddMul(e, f))        // 8 + 12.5 * 2.567\n    fmt.Println(d.SubMul(e, f))        // 8 - 12.5 * 2.567\n    fmt.Println(d.PowInt(2))           // 8²\n\n    fmt.Println(d.Quo(e))              // 8 / 12.5\n    fmt.Println(d.AddQuo(e, f))        // 8 + 12.5 / 2.567\n    fmt.Println(d.SubQuo(e, f))        // 8 - 12.5 / 2.567\n    fmt.Println(d.QuoRem(e))           // 8 div 12.5, 8 mod 12.5\n    fmt.Println(d.Inv())               // 1 / 8\n\n    fmt.Println(decimal.Sum(d, e, f))  // 8 + 12.5 + 2.567\n    fmt.Println(decimal.Mean(d, e, f)) // (8 + 12.5 + 2.567) / 3\n    fmt.Println(decimal.Prod(d, e, f)) // 8 * 12.5 * 2.567\n\n    // Transcendental functions\n    fmt.Println(e.Sqrt())              // √12.5\n    fmt.Println(e.Exp())               // exp(12.5)\n    fmt.Println(e.Expm1())             // exp(12.5) - 1\n    fmt.Println(e.Log())               // ln(12.5)\n    fmt.Println(e.Log1p())             // ln(12.5 + 1)\n    fmt.Println(e.Log2())              // log₂(12.5)\n    fmt.Println(e.Log10())             // log₁₀(12.5)\n    fmt.Println(e.Pow(d))              // 12.5⁸\n\n    // Rounding to 2 decimal places\n    fmt.Println(g.Round(2))            // 7.90\n    fmt.Println(g.Ceil(2))             // 7.90\n    fmt.Println(g.Floor(2))            // 7.89\n    fmt.Println(g.Trunc(2))            // 7.89\n\n    // Conversions\n    fmt.Println(f.Int64(9))            // 2 567000000\n    fmt.Println(f.Float64())           // 2.567\n    fmt.Println(f.String())            // 2.567\n\n    // Formatting\n    fmt.Printf(\"%.2f\", f)              // 2.57\n    fmt.Printf(\"%.2k\", f)              // 256.70%\n}\n```\n\n## Documentation\n\nFor detailed documentation and additional examples, visit the package\n[documentation](https://pkg.go.dev/github.com/govalues/decimal#section-documentation).\nFor examples related to financial calculations, see the `money` package\n[documentation](https://pkg.go.dev/github.com/govalues/money#section-documentation).\n\n## Comparison\n\nComparison with other popular packages:\n\n| Feature              | govalues  | [cockroachdb/apd] v3.2.1 | [shopspring/decimal] v1.4.0 |\n| -------------------- | --------- | ------------------------ | --------------------------- |\n| Correctly Rounded    | Yes       | No                       | No                          |\n| Speed                | High      | Medium                   | Low[^reason]                |\n| Heap Allocations     | No        | Medium                   | High                        |\n| Precision            | 19 digits | Arbitrary                | Arbitrary                   |\n| Panic Free           | Yes       | Yes                      | No[^divzero]                |\n| Mutability           | Immutable | Mutable[^reason]         | Immutable                   |\n| Mathematical Context | Implicit  | Explicit                 | Implicit                    |\n\n[^reason]: decimal package was created simply because [shopspring/decimal] was\ntoo slow and [cockroachdb/apd] was mutable.\n\n[^divzero]: [shopspring/decimal] panics on division by zero.\n\n### Benchmarks\n\n```text\ngoos: linux\ngoarch: amd64\npkg: github.com/govalues/decimal-tests\ncpu: AMD Ryzen 7 3700C  with Radeon Vega Mobile Gfx \n```\n\n| Test Case | Expression            | govalues | [cockroachdb/apd] v3.2.1 | [shopspring/decimal] v1.4.0 | govalues vs cockroachdb | govalues vs shopspring |\n| --------- | --------------------- | -------: | -----------------------: | --------------------------: | ----------------------: | ---------------------: |\n| Add       | 5 + 6                 |   16.06n |                   74.88n |                     140.90n |                +366.22% |               +777.33% |\n| Mul       | 2 * 3                 |   16.93n |                   62.20n |                     146.00n |                +267.40% |               +762.37% |\n| Quo       | 2 / 4 (exact)         |   59.52n |                  176.95n |                     657.40n |                +197.30% |              +1004.50% |\n| Quo       | 2 / 3 (inexact)       |  391.60n |                  976.80n |                    2962.50n |                +149.39% |               +656.42% |\n| PowInt    | 1.1^60                |  950.90n |                 3302.50n |                    4599.50n |                +247.32% |               +383.73% |\n| PowInt    | 1.01^600              |    3.45µ |                   10.67µ |                      18.67µ |                +209.04% |               +440.89% |\n| PowInt    | 1.001^6000            |    5.94µ |                   20.50µ |                     722.22µ |                +244.88% |             +12052.44% |\n| Sqrt      | √2                    |    3.40µ |                    4.96µ |                    2101.86µ |                 +46.00% |             +61755.71% |\n| Exp       | exp(0.5)              |    8.35µ |                   39.28µ |                      20.06µ |                +370.58% |               +140.32% |\n| Log       | ln(0.5)               |   54.89µ |                  129.01µ |                     151.55µ |                +135.03% |               +176.10% |\n| Parse     | 1                     |   16.52n |                   76.30n |                     136.55n |                +362.00% |               +726.82% |\n| Parse     | 123.456               |   47.37n |                  176.90n |                     242.60n |                +273.44% |               +412.14% |\n| Parse     | 123456789.1234567890  |   85.49n |                  224.15n |                     497.95n |                +162.19% |               +482.47% |\n| String    | 1                     |    5.11n |                   19.57n |                     198.25n |                +283.21% |              +3783.07% |\n| String    | 123.456               |   35.78n |                   77.12n |                     228.85n |                +115.52% |               +539.51% |\n| String    | 123456789.1234567890  |   70.72n |                  239.10n |                     337.25n |                +238.12% |               +376.91% |\n| Telco     | (see [specification]) |  137.00n |                  969.40n |                    3981.00n |                +607.33% |              +2804.78% |\n\nThe benchmark results shown in the table are provided for informational purposes only and may vary depending on your specific use case.\n\n[codecov]: https://codecov.io/gh/govalues/decimal\n[codecovb]: https://img.shields.io/codecov/c/github/govalues/decimal/main?color=brightcolor\n[goreport]: https://goreportcard.com/report/github.com/govalues/decimal\n[goreportb]: https://goreportcard.com/badge/github.com/govalues/decimal\n[github]: https://github.com/govalues/decimal/actions/workflows/go.yml\n[githubb]: https://img.shields.io/github/actions/workflow/status/govalues/decimal/go.yml\n[godoc]: https://pkg.go.dev/github.com/govalues/decimal#section-documentation\n[godocb]: https://img.shields.io/badge/go.dev-reference-blue\n[version]: https://go.dev/dl\n[versionb]: https://img.shields.io/github/go-mod/go-version/govalues/decimal?label=go\n[license]: https://en.wikipedia.org/wiki/MIT_License\n[licenseb]: https://img.shields.io/github/license/govalues/decimal?color=blue\n[awesome]: https://github.com/avelino/awesome-go#financial\n[awesomeb]: https://awesome.re/mentioned-badge.svg\n[cockroachdb/apd]: https://pkg.go.dev/github.com/cockroachdb/apd\n[shopspring/decimal]: https://pkg.go.dev/github.com/shopspring/decimal\n[mongo-driver/bson]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueUnmarshaler\n[encoding/json]: https://pkg.go.dev/encoding/json#Unmarshaler\n[encoding/xml]: https://pkg.go.dev/encoding#TextUnmarshaler\n[database/sql]: https://pkg.go.dev/database/sql#Scanner\n[specification]: https://speleotrove.com/decimal/telcoSpec.html\n[fuzz testing]: https://github.com/govalues/decimal-tests\n[half-to-even]: https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgovalues%2Fdecimal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgovalues%2Fdecimal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgovalues%2Fdecimal/lists"}