Long vs BigDecimal for Money: 10 Community Perspectives

The article explores the common dilemma of choosing between Long and BigDecimal for monetary values, summarizing ten distinct community suggestions ranging from using Long, BigDecimal, String, Protobuf, custom types, leadership advice, AI assistance, to minimalist integer approaches.

macrozheng
macrozheng
macrozheng
Long vs BigDecimal for Money: 10 Community Perspectives

Today a popular question surfaced online: should monetary amounts be stored using Long or BigDecimal?

Long

Interpretation: The amount is expressed in cents without a decimal point, so precision issues are irrelevant, and the Long range is sufficient.

BigDecimal

Interpretation: Most developers use BigDecimal for precise calculations; using Long is considered unprofessional and less adaptable.

Long and BigDecimal

Interpretation: Adults want the best of both worlds—use Long for whole‑unit amounts like price, and BigDecimal for rates or exchange values that require fractional precision.

String

Interpretation: Everything can be stored as a String, but you must implement all parsing and validation logic yourself, a skill for advanced developers.

Protobuf

Interpretation: Protobuf does not natively support BigDecimal; you can only use String or a custom type, which may incur a slight performance penalty.

Custom Type

Interpretation: Designing a custom monetary type reflects good architectural thinking; the implementation should naturally express business requirements and remain maintainable.

Follow the Leader

Interpretation: When leadership dictates a solution, it’s not a technical issue—simply comply while protecting your own interests.

Ask AI

Interpretation: Leveraging large language models can quickly provide a thorough answer, showcasing the latest productivity tools for tech professionals.

Frugal Approach

Interpretation: For small‑scale amounts, using smaller primitives like int, short, or even byte is sufficient; there’s no need for Long or BigDecimal.

Random Choice

Interpretation: Some suggestions appear whimsical, reflecting personal preference rather than technical merit.

Author: 萤火架构 Source: juejin.cn/post/7314928953193578505
Javadata typesBigDecimalLong
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.