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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:07:37+00:00 2026-05-23T10:07:37+00:00

I am writing a program that has to round very large and precise numbers

  • 0

I am writing a program that has to round very large and precise numbers (possibly many more significant digits than even double could handle), and am using BigDecimals.

Is there a way to make BigDecimal round based on place and not significant figures?

That is, I need 0.5 to round to 1 and 0.4 to round to 0, but since they are the same number of significant figures, BigDecimal refuses to round either of them.

  • 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-23T10:07:38+00:00Added an answer on May 23, 2026 at 10:07 am

    I suspect you want setScale:

    import java.math.*;
    
    public class Test
    {
        public static void main(String[] args)
        {
            showRounded(new BigDecimal("0.4"));
            showRounded(new BigDecimal("0.5"));
        }
    
        static void showRounded(BigDecimal input)
        {
            BigDecimal output = input.setScale(0, BigDecimal.ROUND_HALF_UP);
            System.out.println(input + " => " + output);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a C++ program that has a large number of classes. In my
I'm writing a program that has an NSView embedded in an NSScrollView which user
I am writing a program that manages a bunch of timers. The user has
Is the Go map type thread safe? I have a program that has many
I am writing a program that has to copy a sizeable, but not huge
I'm writing a program in C# that has a custom collection. The custom collection
I'm writing a program that has two main functions. Each of the functions will
I'm writing a program that has to remove separator characters from quoted strings in
I'm writing a program that has two libraries that I need to use: v8,
Unfortunately I don't know much networks. I am writing a program that has two

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.