Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:59:54+00:00 2026-06-09T13:59:54+00:00

I need to represent some numbers in Java with perfect precision and fixed number

  • 0

I need to represent some numbers in Java with perfect precision and fixed number of decimal points after decimal point; after that decimal point, I don’t care. (More concretely – money and percentages.)

I used Java’s own BigDecimal now, but I found out, that it’s really slow and it starts to show in my application.

So I want to solve it with a “regular” integers and a fixed-point arithmetics (long integers have big enough precision for my purposes).

Now, I would think that I am not the first one who has this kind of problem and there would be already a library for that, that already has multiplication/division implemented – but it seems that it isn’t.

Now, I very probably can write it myself (and I probably will), but really, am I really the first person that needs this? Isn’t there already some library for that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:59:56+00:00Added an answer on June 9, 2026 at 1:59 pm

    Are you completely sure BigDecimal is the performance problem? Did you use a profiler to find out? If yes, two options that could help are:

    1) Use long and multiply all values by a factor (for example 100 if you are interested in cents).

    2) Use a specially designed class that implements something similar to BigDecimal, but using long internally. I don’t know if a good open source library exists (maybe the Java Math Fixed Point Library?). I wrote one such class myself quite a long time ago (2001 I believe) for J2ME. It’s a bit tricky to get right. Please note BigDecimal uses a long internally as well except if high precision is needed, so this solution will only help a tiny bit in most cases.

    Using double isn’t a good option in many cases, because of rounding and precision problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to build a class that will represent a row in some table
I need to represent an IEEE 754-1985 double (64-bit) floating point number in a
I want to represent a floating-point number as a string rounded to some number
I need to do some decimal place formatting in python. Preferably, the floating point
I need to generate random numbers that have a beta distribution in some speed
I have some data in a database that I need represented in an XML
We need to represent huge numbers in our application. We're doing this using integer
I need to represent that a property on an object is different from that
I'm performing some data type conversions where I need to represent uint , long
I need a function in Java to give me number of bytes needed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.