Decimal128 (High-Precision Decimal)

Last updated: 2026-10-09

Decimal128 (High-Precision Decimal)

Decimal128 is MongoDB's high-precision decimal type, based on the IEEE 754-2008 decimal floating-point standard, with 34 significant decimal digits. It suits money, rates, and other data needing exact arithmetic, avoiding Double's binary rounding errors. Construct with `Decimal128('19.99')` or the mongosh 5.0+ shorthand `NumberDecimal('19.99')`.

CategoryBSON Types
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

Decimal128("<decimal string>")
NumberDecimal("<decimal string>")  // mongosh 5.0+
{ price: Decimal128("19.99") }

Returns:Returns a Decimal128 BSON value

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// Decimal128: construct and exact match
use shop
db.prices.insertOne({ item: 'apple', price: Decimal128('19.99') })
db.prices.find({ price: { $eq: Decimal128('19.99') } })

Output:

{ _id: ObjectId('...'), item: 'apple', price: Decimal128('19.99') }

📌 Notes

📚 Related Tutorials

❓ FAQ

QWhat is the difference between Decimal128 and Double?
ADouble is binary floating point where 0.1 is inexact; Decimal128 stores decimal digits (34 significant) for exact money math.
QHow large a value can Decimal128 hold?
AExponent range is roughly ±6143, value range about ±9.99×10^6144 — beyond any business need.
QWhy store prices as Decimal128?
AMoney needs exact decimal arithmetic; Double sums drift (e.g. 0.30000000000000004), breaking reconciliation.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏