decimal
478
Stars
112
Forks
10
Watchers
0
Open Issues
Apache-2.0
许可证
Elixir
语言
2013-11-16
创建时间
2026-11-02
最近更新
项目能做什么
任意精度的十进制数运算库。
来源:AI 基于仓库事实生成
· 内容以仓库实际 README 为准
使用说明 查看原始 README 原仓库文档
中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# Decimal
Arbitrary precision decimal arithmetic.
## Concept
Decimal represents values internally using three integers: a sign, a coefficient, and an exponent.
In this way, numbers of any size and with any number of decimal places can be represented exactly.
```elixir
Decimal.new(_sign = 1, _coefficient = 42, _exponent = 0) #=> Decimal.new("42")
Decimal.new(-1, 42, 0) #=> Decimal.new("-42")
Decimal.new(1, 42, -1) #=> Decimal.new("4.2")
Decimal.new(1, 42, -20) #=> Decimal.new("4.2E-19")
Decimal.new(1, 42, 20) #=> Decimal.new("4.2E+21")
Decimal.new(1, 123456789987654321, -9) #=> Decimal.new("123456789.987654321")
```
For calculations, the amount of desired precision - that is, the number of
decimal digits in the coefficient - can be specified.
## Handling untrusted input
Decimal can represent compact values with very large exponents, such as
`1e1000000`. These values are valid decimals, but some operations can require
memory or CPU proportional to the expanded size of the number. This matters when
decimals are parsed from user input, JSON payloads, form fields, database
fields, or other external data.
Use bounded parsing for untrusted input:
```elixir
Decimal.parse(input, max_digits: 100, max_exponent: 1000)
Decimal.cast(input, max_digits: 100, max_exponent: 1000)
```
`Decimal.new/1` with an integer and `Decimal.new/3` take their arguments as
given, without limits. Use `Decimal.cast/2`, which applies the limits to
integers and decimals as well as strings, when those come from untrusted input.
Use bounded output when rendering decimals in formats that may expand the
exponent:
```elixir
Decimal.to_string(decimal, :normal, max_digits: 1000)
Decimal.to_string(decimal, :xsd, max_digits: 1000)
```
The default scientific string format is compact for large positive exponents,
but `:normal` and `:xsd` output can materialize many zeroes. APIs that convert
to an integer or otherwise need the expanded value may also be expensive for
large exponents. `Decimal.Context` supports finite `emax` and `emin` values to
limit operation results, but context limits do not validate already-created
decimals and should not replace parse/cast limits for untrusted input.
## Usage
Add Decimal as a dependency in your `mix.exs` file:
```elixir
def deps do
[{:decimal, "~> 2.0"}]
end
```
Next, run `mix deps.get` in your shell to fetch and compile `Decimal`. Start an
interactive Elixir shell with `iex -S mix`:
```elixir
iex> alias Decimal, as: D
iex> D.add(6, 7)
Decimal.new("13")
iex> D.div(1, 3)
Decimal.new("0.3333333333333333333333333333")
iex> D.new("0.33")
Decimal.new("0.33")
```
## Examples
### Using the context
The context specifies the maximum precision of the result of calculations and
the rounding algorithm if the result has a higher precision than the specified
maximum. It also holds the list of trap enablers and the current set
flags.
The context is stored in the process dictionary. You don't have to pass the
context around explicitly and the flags
阅读完整原文
商业机会分析 AI 生成
嵌入式金融级计费与多币种核算引擎(SaaS/API)
| 产品构想 | 基于 Elixir 高并发与 Decimal 精确计算能力,构建面向出海企业的计费与多币种转换、结算账单核算服务。 |
| 核心功能 | 高精度计费规则配置、汇率自动换算与尾差处理、按调用量/订阅计费的账单生成、防精度舍入漏洞的审计日志。 |
| 目标用户 | 跨境电商独立站、SaaS 平台、出海应用开发者。 |
| 难度/周期 | 高 · 3-6个月 · 成本:中等(主要是服务器与国际支付/汇率数据源接入成本) |
| 收费模式 | 按月订阅费 + 超额账单处理量梯次计费 |
| 竞争风险 | 计费系统迁移成本高,市场竞争激烈(如 Stripe Billing),对系统容灾与合规性要求极高。 |
| 依据 | AI推测 |
面向 Elixir 技术栈的企业级安全审计与技术支持服务
| 产品构想 | 围绕 Decimal 的输入校验(针对大指数 DoS 攻击)及数值精度风险,为金融/电商领域的 Elixir 团队提供专项代码安全审计与技术支持。 |
| 核心功能 | 精度丢失隐患扫描、反 DoS 输入防御(max_digits/max_exponent)合规检查、Ecto 复杂数值计算性能优化报告。 |
| 目标用户 | 使用 Elixir/Phoenix 开发金融交易、数字资产、电商核心系统的技术团队负责人。 |
| 难度/周期 | 中等 · 2-4周 · 成本:低(主要为人力与工具开发成本) |
| 收费模式 | 单次代码审计费、年度技术咨询/应急响应服务费 |
| 竞争风险 | Elixir 商业化市场基数较小,客群有限,难以形成规模化被动收入。 |
| 依据 | 数据支持的判断 |
高精度财务分录与对账中间件(开箱即用方案)
| 产品构想 | 利用 Decimal 构建标准化的财务对账引擎,支持导入银行/支付网关账单,自动处理高精度拆账、平账及异常差额报警。 |
| 核心功能 | 复式记账法引擎、千万级交易流水自动轧差比对、舍入误差自动归并、异常对账报告生成。 |
| 目标用户 | 中小型电商平台财务人员、企业 ERP 系统集成商。 |
| 难度/周期 | 中等 · 2-3个月 · 成本:低(基础云服务器即可运行) |
| 收费模式 | 私有化部署买断许可 + 维保费,或云端按导入数据条数计费 |
| 竞争风险 | 需要深入理解不同国家的会计准则与数据接口格式,需求定制化程度高。 |
| 依据 | 尚需验证的假设 |
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心
竞品与相似项目 GitHub Search 真实检索
| 项目 | 中文简介 | Stars | 语言 |
|---|---|---|---|
| shopspring/decimal | 中文介绍暂未生成 Arbitrary-precision fixed-point decimal numbers in Go |
7,520 | Go |
| MikeMcl/decimal.js | 中文介绍暂未生成 An arbitrary-precision Decimal type for JavaScript |
7,272 | JavaScript |
| MikeMcl/bignumber.js | 中文介绍暂未生成 A JavaScript library for arbitrary-precision decimal and non |
7,015 | JavaScript |
| MikeMcl/big.js | 中文介绍暂未生成 A small, fast JavaScript library for arbitrary-precision dec |
5,203 | JavaScript |
| ulfjack/ryu | 中文介绍暂未生成 Converts floating point numbers to decimal strings |
1,357 | C++ |
| paupino/rust-decimal | 中文介绍暂未生成 Decimal number implementation written in pure Rust suitable |
1,342 | Rust |
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。
项目优势与风险
| 技术成熟度 | 创建于 2013-11-16,近 30 天仍在推送,发布过 28 个 Release |
| 社区活跃 | Star 478 / Fork 112 / Issue 0(数据支持,可自行核实) |
| 许可证 | Apache-2.0 |
| 主要风险 | 上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价 |
安装与使用
快速开始(以仓库 README 为准)
git clone https://github.com/ericmj/decimal.git cd decimal # 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。