{"id":13412837,"url":"https://github.com/shopspring/decimal","last_synced_at":"2025-09-09T20:42:51.189Z","repository":{"id":27843446,"uuid":"31333618","full_name":"shopspring/decimal","owner":"shopspring","description":"Arbitrary-precision fixed-point decimal numbers in Go","archived":false,"fork":false,"pushed_at":"2025-06-24T23:04:24.000Z","size":262,"stargazers_count":6890,"open_issues_count":145,"forks_count":645,"subscribers_count":72,"default_branch":"master","last_synced_at":"2025-08-14T17:43:43.366Z","etag":null,"topics":["bignumber","decimals","go","golang","money","precision"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shopspring.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2015-02-25T20:12:57.000Z","updated_at":"2025-08-14T16:46:58.000Z","dependencies_parsed_at":"2023-02-10T18:15:49.241Z","dependency_job_id":"5750e131-2509-46d0-b733-c2279aa3f2a8","html_url":"https://github.com/shopspring/decimal","commit_stats":{"total_commits":168,"total_committers":68,"mean_commits":"2.4705882352941178","dds":0.8154761904761905,"last_synced_commit":"a1bdfc355e9c71119322b748c95f7d6b82566e30"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/shopspring/decimal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopspring%2Fdecimal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopspring%2Fdecimal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopspring%2Fdecimal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopspring%2Fdecimal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shopspring","download_url":"https://codeload.github.com/shopspring/decimal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopspring%2Fdecimal/sbom","scorecard":{"id":820695,"data":{"date":"2025-08-11","repo":{"name":"github.com/shopspring/decimal","commit":"08afb35517362df21914209a026f65bb33275fbc"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.1,"checks":[{"name":"Code-Review","score":5,"reason":"Found 16/30 approved changesets -- score normalized to 5","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":"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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.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":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/shopspring/decimal/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/shopspring/decimal/ci.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction 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":"Maintained","score":2,"reason":"2 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"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":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"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":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"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 27 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-23T15:28:03.751Z","repository_id":27843446,"created_at":"2025-08-23T15:28:03.751Z","updated_at":"2025-08-23T15:28:03.751Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274358733,"owners_count":25270681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["bignumber","decimals","go","golang","money","precision"],"created_at":"2024-07-30T20:01:29.872Z","updated_at":"2025-09-09T20:42:51.163Z","avatar_url":"https://github.com/shopspring.png","language":"Go","readme":"# decimal\n\n[![ci](https://github.com/shopspring/decimal/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/shopspring/decimal/actions/workflows/ci.yml)\n[![GoDoc](https://godoc.org/github.com/shopspring/decimal?status.svg)](https://godoc.org/github.com/shopspring/decimal) \n[![Go Report Card](https://goreportcard.com/badge/github.com/shopspring/decimal)](https://goreportcard.com/report/github.com/shopspring/decimal)\n\nArbitrary-precision fixed-point decimal numbers in go.\n\n_Note:_ Decimal library can \"only\" represent numbers with a maximum of 2^31 digits after the decimal point.\n\n## Features\n\n * The zero-value is 0, and is safe to use without initialization\n * Addition, subtraction, multiplication with no loss of precision\n * Division with specified precision\n * Database/sql serialization/deserialization\n * JSON and XML serialization/deserialization\n\n## Install\n\nRun `go get github.com/shopspring/decimal`\n\n## Requirements \n\nDecimal library requires Go version `\u003e=1.10`\n\n## Documentation\n\nhttp://godoc.org/github.com/shopspring/decimal\n\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shopspring/decimal\"\n)\n\nfunc main() {\n\tprice, err := decimal.NewFromString(\"136.02\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tquantity := decimal.NewFromInt(3)\n\n\tfee, _ := decimal.NewFromString(\".035\")\n\ttaxRate, _ := decimal.NewFromString(\".08875\")\n\n\tsubtotal := price.Mul(quantity)\n\n\tpreTax := subtotal.Mul(fee.Add(decimal.NewFromFloat(1)))\n\n\ttotal := preTax.Mul(taxRate.Add(decimal.NewFromFloat(1)))\n\n\tfmt.Println(\"Subtotal:\", subtotal)                      // Subtotal: 408.06\n\tfmt.Println(\"Pre-tax:\", preTax)                         // Pre-tax: 422.3421\n\tfmt.Println(\"Taxes:\", total.Sub(preTax))                // Taxes: 37.482861375\n\tfmt.Println(\"Total:\", total)                            // Total: 459.824961375\n\tfmt.Println(\"Tax rate:\", total.Sub(preTax).Div(preTax)) // Tax rate: 0.08875\n}\n```\n\n## Alternative libraries\n\nWhen working with decimal numbers, you might face problems this library is not perfectly suited for. \nFortunately, thanks to the wonderful community we have a dozen other libraries that you can choose from.  \nExplore other alternatives to find the one that best fits your needs :)  \n\n* [cockroachdb/apd](https://github.com/cockroachdb/apd) - arbitrary precision, mutable and rich API similar to `big.Int`, more performant than this library \n* [alpacahq/alpacadecimal](https://github.com/alpacahq/alpacadecimal) - high performance, low precision (12 digits), fully compatible API with this library \n* [govalues/decimal](https://github.com/govalues/decimal) - high performance, zero-allocation, low precision (19 digits)\n* [greatcloak/decimal](https://github.com/greatcloak/decimal) - fork focusing on billing and e-commerce web application related use cases, includes out-of-the-box BSON marshaling support\n\n## FAQ\n\n#### Why don't you just use float64?\n\nBecause float64 (or any binary floating point type, actually) can't represent\nnumbers such as `0.1` exactly.\n\nConsider this code: http://play.golang.org/p/TQBd4yJe6B You might expect that\nit prints out `10`, but it actually prints `9.999999999999831`. Over time,\nthese small errors can really add up!\n\n#### Why don't you just use big.Rat?\n\nbig.Rat is fine for representing rational numbers, but Decimal is better for\nrepresenting money. Why? Here's a (contrived) example:\n\nLet's say you use big.Rat, and you have two numbers, x and y, both\nrepresenting 1/3, and you have `z = 1 - x - y = 1/3`. If you print each one\nout, the string output has to stop somewhere (let's say it stops at 3 decimal\ndigits, for simplicity), so you'll get 0.333, 0.333, and 0.333. But where did\nthe other 0.001 go?\n\nHere's the above example as code: http://play.golang.org/p/lCZZs0w9KE\n\nWith Decimal, the strings being printed out represent the number exactly. So,\nif you have `x = y = 1/3` (with precision 3), they will actually be equal to\n0.333, and when you do `z = 1 - x - y`, `z` will be equal to .334. No money is\nunaccounted for!\n\nYou still have to be careful. If you want to split a number `N` 3 ways, you\ncan't just send `N/3` to three different people. You have to pick one to send\n`N - (2/3*N)` to. That person will receive the fraction of a penny remainder.\n\nBut, it is much easier to be careful with Decimal than with big.Rat.\n\n#### Why isn't the API similar to big.Int's?\n\nbig.Int's API is built to reduce the number of memory allocations for maximal\nperformance. This makes sense for its use-case, but the trade-off is that the\nAPI is awkward and easy to misuse.\n\nFor example, to add two big.Ints, you do: `z := new(big.Int).Add(x, y)`. A\ndeveloper unfamiliar with this API might try to do `z := a.Add(a, b)`. This\nmodifies `a` and sets `z` as an alias for `a`, which they might not expect. It\nalso modifies any other aliases to `a`.\n\nHere's an example of the subtle bugs you can introduce with big.Int's API:\nhttps://play.golang.org/p/x2R_78pa8r\n\nIn contrast, it's difficult to make such mistakes with decimal. Decimals\nbehave like other go numbers types: even though `a = b` will not deep copy\n`b` into `a`, it is impossible to modify a Decimal, since all Decimal methods\nreturn new Decimals and do not modify the originals. The downside is that\nthis causes extra allocations, so Decimal is less performant.  My assumption\nis that if you're using Decimals, you probably care more about correctness\nthan performance.\n\n## License\n\nThe MIT License (MIT)\n\nThis is a heavily modified fork of [fpd.Decimal](https://github.com/oguzbilgic/fpd), which was also released under the MIT License.\n","funding_links":[],"categories":["HarmonyOS","Go","开源类库","Financial","Open source library","金融","Popular","Repositories","\u003cspan id=\"金融-financial\"\u003e金融 Financial\u003c/span\u003e","金融领域相关库`处理货币与金融领域的库`","Relational Databases","財經","金融领域相关库","Libraries","财经"],"sub_categories":["Windows Manager","数学计算","Advanced Console UIs","Search and Analytic Databases","Mathematical Calculations","检索及分析资料库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","SQL 查询语句构建库","高級控制台界面","Go","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshopspring%2Fdecimal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshopspring%2Fdecimal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshopspring%2Fdecimal/lists"}