# OCaml needs an arbitrary-precision decimal type

**URL:** <https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735>\
**Category:** Ecosystem\
**Created:** [November 9, 2020, 9:41pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735 "2020-11-09T21:41:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [November 9, 2020, 9:41pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/1 "2020-11-09T21:41:59Z")

</div>

I’ve mentioned this before: [What libraries are missing?](https://discuss.ocaml.org/t/what-libraries-are-missing/6543/15)

But pulling it into a new thread because I have a specific ask: is someone willing to contribute a decimal number implementation to OCaml?

I realize OCaml has historically had a minimalist standard library philosophy, e.g. it’s reasonable to not include a JSON data type, but I believe decimal numbers are a fairly fundamental type especially for business applications. Major industrial language platforms tend to agree:

- .NET: [https://docs.microsoft.com/en-us/dotnet/api/system.decimal?view=netcore-3.1](https://docs.microsoft.com/en-us/dotnet/api/system.decimal?view=netcore-3.1)
- Java: [https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html](https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html)
- Python: [https://docs.python.org/3.8/library/decimal.html](https://docs.python.org/3.8/library/decimal.html)
- Ruby: [https://ruby-doc.org/stdlib-2.5.1/libdoc/bigdecimal/rdoc/BigDecimal.html](https://ruby-doc.org/stdlib-2.5.1/libdoc/bigdecimal/rdoc/BigDecimal.html)
- ObjC/Swift: [https://developer.apple.com/documentation/foundation/decimal](https://developer.apple.com/documentation/foundation/decimal)

And even newer ones:

- Crystal: [https://crystal-lang.org/api/0.24.2/BigDecimal.html](https://crystal-lang.org/api/0.24.2/BigDecimal.html)
- Zig (proposed): [https://github.com/ziglang/zig/issues/4221](https://github.com/ziglang/zig/issues/4221)

So, I thought I’d bring it up again, as it’s really pretty foundational IMHO.

---

<div class="post-metadata">

**Author:** ![Drup](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/drup/32/35_2.png) [@Drup](https://discuss.ocaml.org/u/Drup)\
**Post date:** [November 9, 2020, 10:04pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/2 "2020-11-09T22:04:08Z")

</div>

You’re going at this wrong.

The first step of putting anything in the stdlib is to actually write a library that does it.

So, if you want it, start by writing the library. Publish it, iterate on the design and then maybe propose it. Worse case, you’ll have a good decimal library.

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [November 9, 2020, 10:06pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/3 "2020-11-09T22:06:59Z")

</div>

Well, I really do believe it should be in the standard library, but I have nothing against starting it as a separate package. In either case, my main question is still: is anyone willing to contribute one?

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [November 11, 2020, 1:36am UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/4 "2020-11-11T01:36:41Z")

</div>

I’ve kicked off the process of releasing Jane Street’s arbitrary precision decimal type, called Bigdecimal. It should hit github in a few days, I expect.

y

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [November 11, 2020, 3:59am UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/5 "2020-11-11T03:59:06Z")

</div>

Thank you very much, that is very generous. I’ve been working on a straight-up port of the Python [decimal module](https://github.com/python/cpython/blob/23831a7a90956e38b7d70304bb6afe30d37936de/Lib/_pydecimal.py) to OCaml for the past few days, but of course Jane Street’s `Bigdecimal` will be much more trustworthy than my home-grown effort 🙂

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [November 20, 2020, 5:23pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/6 "2020-11-20T17:23:35Z")

</div>

Our Bigdecimal library is now live:

> **[janestreet/bigdecimal](https://github.com/janestreet/bigdecimal)**
>
> Arbitrary-precision decimal based on Zarith. Contribute to janestreet/bigdecimal development by creating an account on GitHub.

It won’t be in the ordinary Opam repo until our next stable release, which is scheduled for early 2021.

---

<div class="post-metadata">

**Author:** ![rbjorklin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rbjorklin/32/1126_2.png) [@rbjorklin](https://discuss.ocaml.org/u/rbjorklin)\
**Post date:** [June 13, 2021, 5:10pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/7 "2021-06-13T17:10:18Z")

</div>

I’m trying to find bigdecimal on opam but unless it has a non-obvious name I’m guessing it got overlooked for the v0.14.1 release that was made early 2021?

Is there another release on the horizon where bigdecimal could be included?

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [June 13, 2021, 8:21pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/8 "2021-06-13T20:21:14Z")

</div>

v0.14.1 refers to a patch release, which for Jane Street packages, is usually things like fixing compatibility on different platforms or adjusting opam dependencies/constraints and things. The next “stable release” would be v0.15, which hasn’t happened yet, unfortunately.

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [June 13, 2021, 10:42pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/9 "2021-06-13T22:42:55Z")

</div>

My alternative may work for your use case: [opam - decimal](http://opam.ocaml.org/packages/decimal/)

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [March 31, 2022, 9:49pm UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/10 "2022-03-31T21:49:23Z")

</div>

In case anyone is interested, bigdecimal is part of our latest stable release, which is now on opam!

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [April 1, 2022, 2:26am UTC](https://discuss.ocaml.org/t/ocaml-needs-an-arbitrary-precision-decimal-type/6735/11 "2022-04-01T02:26:52Z")

</div>

> [@Yaron\_Minsky](#):
>
> not on opam

“now” on opam, I think 😛
