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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:08:37+00:00 2026-06-16T00:08:37+00:00

I have a BigDecimal object and i want to convert it to string. The

  • 0

I have a BigDecimal object and i want to convert it to string.
The problem is that my value got fraction and i get a huge number (in length) and i only need the original number in string for example:
for

BigDecimal bd = new BigDecimal(10.0001)
System.out.println(bd.toString());
System.out.println(bd.toPlainString());

the output is:

10.000099999999999766941982670687139034271240234375
10.000099999999999766941982670687139034271240234375

and i need the out put to be exactly the number 10.0001 in string

  • 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-16T00:08:38+00:00Added an answer on June 16, 2026 at 12:08 am

    To get exactly 10.0001 you need to use the String constructor or valueOf (which constructs a BigDecimal based on the canonical representation of the double):

    BigDecimal bd = new BigDecimal("10.0001");
    System.out.println(bd.toString()); // prints 10.0001
    //or alternatively
    BigDecimal bd = BigDecimal.valueOf(10.0001);
    System.out.println(bd.toString()); // prints 10.0001
    

    The problem with new BigDecimal(10.0001) is that the argument is a double and it happens that doubles can’t represent 10.0001 exactly. So 10.0001 is “transformed” to the closest possible double, which is 10.000099999999999766941982670687139034271240234375 and that’s what your BigDecimal shows.

    For that reason, it rarely makes sense to use the double constructor.

    You can read more about it here, Moving decimal places over in a double

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

Sidebar

Related Questions

I have to convert an incoming String field into a BigDecimal field that would
I have a BigDecimal value and I want to know if the number of
I have the following method: protected BigDecimal stringToBigDecimal(String value) throws ParseException { if (Pattern.matches([\\d,.]+,
I have a BigDecimal object, myNumber , with unknown length. For example: 12345678 .
I have a data object that is holding a meny BigDecimal object as well
I have a prepared statement. I call stmt.setBigDecimal(BigDecimal.valueOf(0.9)) the problem is that in the
I have a string array in an object which is storing a decimal value.
I want to divide a bigdecimal value with an integer.i have rounded the bigdecimal
I do have a static metamodel with a NUMBER (actually, BigDecimal, don't ask why)
In a Wicket app, I have a decimal number text field: TextField<BigDecimal> f =

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.