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 6897133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:07:51+00:00 2026-05-27T07:07:51+00:00

I know the problem with double/float, and it’s recommended to use BigDecimal instead of

  • 0

I know the problem with double/float, and it’s recommended to use BigDecimal instead of double/float to represent monetary fields. But double/float is more effective and space-saving. Then my question is:
It’s acceptable to use double/float to represent monetary fields in Java class, but use BigDecimal to take care of the arithmetic (i.e. convert double/float to BigDecimal before any arithmetic) and equal-checking?

The reason is to save some space. And I really see lots of projects are using double/float to represent the monetary fields.

Is there any pitfall for this?
Thanks in advance.

  • 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-05-27T07:07:52+00:00Added an answer on May 27, 2026 at 7:07 am

    No, you can’t.

    Suppose double is enough to store two values x and y. Then you convert them to safe BigDecimal and multiple them. The result is accurate, however if you store the multiplication result back in double, chances are you will loose the precision. Proof:

    double x = 1234567891234.0;
    double y = 1234567891234.0;
    System.out.println(x);
    System.out.println(y);
    
    BigDecimal bigZ = new BigDecimal(x).multiply(new BigDecimal(y));
    double z = bigZ.doubleValue();
    System.out.println(bigZ);
    System.out.println(z);
    

    Results:

    1.234567891234E12          //precise 'x'
    1.234567891234E12          //precise 'y'
     1524157878065965654042756  //precise 'x * y'
    1.5241578780659657E24      //loosing precision
    

    x and y are accurate, as well as the multiplication using BigDecimal. However after casting back to double we loose least significant digits.

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

Sidebar

Related Questions

I know I've solved this problem before, but I can't remember or find the
I have a problem with casting from float to double when fread; fread(doublePointer,sizeofFloat,500,f); if
After coming up against this problem myself in trying to implement a generic Vector2<int/float/double>
I know it is an humiliating and basic problem, but I can't align the
Most of you probably know the following problem: You edit an HTML, view the
I don't know the exact problem. I am using flex mx:tree component in flex
I realy dont know what the problem is with VS2010. I created a class,
How do I let Microsoft know about a problem I've found in one of
http://en.wikipedia.org/wiki/Diamond_problem I know what it means, but what steps can I take to avoid
Sometimes I've made a namespace in C# (I don't know if the problem is

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.