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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:11:48+00:00 2026-06-16T23:11:48+00:00

Possible Duplicate: Addition for BigDecimal I feel like I’m missing something obvious, but cannot

  • 0

Possible Duplicate:
Addition for BigDecimal

I feel like I’m missing something obvious, but cannot figure out what it is. I’m trying to use BigDecimal to get the decimal portion of a division between two numbers. A very simple case, 1.00 divided by 3.00 should be 0.(3) repeating. However, I keep getting a result of 1.00.

BigDecimal num = new BigDecimal(1.00).setScale(2);
BigDecimal divisor = new BigDecimal(3.00).setScale(2);

num.divide(divisor, BigDecimal.ROUND_HALF_UP);

System.out.print(num);

My result is 1.00 and I can’t figure out why?

  • 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-16T23:11:49+00:00Added an answer on June 16, 2026 at 11:11 pm

    The result of num.divide is ignored. You need to set that back into a variable

        BigDecimal num = new BigDecimal(1.00).setScale(2);
        BigDecimal divisor = new BigDecimal(3.00).setScale(2);
    
        BigDecimal result = num.divide(divisor, BigDecimal.ROUND_HALF_UP);
    
        System.out.print(result);
    

    This prints 0.33

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

Sidebar

Related Questions

Possible Duplicate: Learning to write a compiler I looked around trying to find out
Possible Duplicate: Addition of two chars produces int Given the following C++ code: unsigned
Possible Duplicate: Strange addition of numeric strings in PHP $r = 1.0 - 0.8
Possible Duplicate: What to do when I want to use database constraints but only
Possible Duplicate: about assembly CF(Carry) and OF(Overflow) flag I'm trying to see if carry
Possible Duplicate: CGFloat addition bug? I have a CGPoint (which is just a struct
Possible Duplicate: Addition turns into concatenation Here's what I have... var srate = Math.round(princ
Possible Duplicate: PHP: The Reflection API - Great Addition To PHP With Little Use
Possible Duplicate: Dynamically adding collapsible elements I've seen a few posts on this but
They think it is: Possible Duplicate: Integer with leading zeroes But if you check

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.