double « bigdecimal « Java Data Type Q&A





1. Why is the Bigdecimal(double d) construction still around?    stackoverflow.com

I've noticed substantial pain over this constructor (even here on Stack Overflow). People use it even though the documentation clearly states:

The results of this constructor can be somewhat unpredictable ...

2. Regarding Big Decimal    stackoverflow.com

I have a csv file where amount and quantity fields are present in each detail record except header and trailer record. Trailer record has a total charge values which is the ...

3. BigDecimal from Double incorrect value?    stackoverflow.com

I am trying to make a BigDecimal from a string. Don't ask me why, I just need it! This is my code:

Double theDouble = new Double(".3");
System.out.println("The Double: " + theDouble.toString());
BigDecimal ...

4. BigDecimal - check value is within double range    stackoverflow.com

I have a Java application which parses a number from somewhere, and checks that it is a valid int (between Integer.MIN_VALUE and Integer.MAX_VALUE) or a valid double (between Double.MIN_VALUE and Double.MAX_VALUE). I'm ...

5. Java BigDecimal difference    stackoverflow.com

I wanted to see if anyone can explain why the following code works with valueOf but not others.

import java.math.BigDecimal; 
public class Change {
   public static void main(String args[]) {
 ...

6. How to get "shortest" BigDecimal that uniquely determines a given double    stackoverflow.com

Basically, I'm curious on how to get hold of new BigDecimal(Double.toString(d)) without going through the process of creating a string. The documentation for Double.toString is quite complex (and interesting). As ...

7. Java:Why should we use BigDecimal instead of Double in the real world?    stackoverflow.com

When dealing with real world monetary values, I am advised to use BigDecimal instead of Double.But I have not got a convincing explanation except, "It is normally done that way". Can you ...

8. Java double vs BigDecimal for latitude/longtitude    stackoverflow.com

When storing latitudes/longtitudes which are typically of the format: 44.087585 (i.e. max 2 numbers before the dot and 6dp) do I need to bother with bigdecimals?

9. Am I using the BigDecimal class correctly? I could really use someone to double check my code to make sure I'm not making rookie mistakes    stackoverflow.com

I've been working on this for a few days. After getting ridiculous double errors, it seemed using BigDecimal was the way to go. Here's the code: http://pastebin.com/rpbNJnHH I've never ...





10. Trouble with BigDecimal and Double    coderanch.com

Hi All , I am having trouble with a double number . I have a number in DB with 15 digits before decimal point and 3 digits after the decimal I need to display it to user on GUI When i convert it to String then it is shown in exponential form with some truncation . I tried some statements with ...

11. Advice on BigDecimal vs. double    coderanch.com

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

12. BigDecimal vs double    coderanch.com

As Campbell mentioned, Effective Java by Joshua Bloch has a very nice, succinct, and compelling explanation of why BigDecimal should be used rather than doubles, especially for monetary calculations. The item is named Avoid float and double if exact answers are required and is Item #31 in the first edition (ISBN-10: 0-201-31005-8) and Item #48 in the second edition (ISBN-10: 0-321-35668-3). ...

13. double or BigDecimal    coderanch.com

Hello Ranchers, In our application,the datatype 'double' has been used for monetary transaction,now there is a calculation of adding two fares,the result is not quite correct. For Ex: sum of 185.70 , 642.20 gives 827.9000000000001, but that is not correct, it should be only 827.90 Is this because of the datatype double? Thank you, ramana.

14. How do i Multiply a BigDecimal by a Double    java-forums.org

Java Code: /** * @(#)DifAnalysis.java * * @https://sites.google.com/site/s0m3b0dysstuff/ * @Ryan Fabela * @version 1.00 2010/9/24 */ import java.util.*; import java.io.*; import java.lang.Math; import java.math.BigDecimal; public class DifAnalysis { public static void main(String[] Arguments){ Scanner oSciNote = new Scanner(System.in); String sSciNoteP1,sSciNoteP2,sTarget,sBase,sBaseminusTarget,sAnswer; BigDecimal SciNoteP1,Base,Target,SciNoteP2,BaseminusTarget,Answer;/* P1 Means out of 3.125 x 10^5 the 3.125 part. P2 means the 10^5 part. target is the target ...

15. BigDecimal vs. double    forums.oracle.com

The problem is that certain numbers that can be exactly represented in a decimal (base 10) number system, such as 0.1, can't be exactly represented in the binary (base 2) number system that Java (and almost all computers) use for doubles. So the doubles sometimes have small differences, and they can add up to a significant difference.

16. double vs. BigDecimal    forums.oracle.com

In our project we used double all the time. Recently we discoverd some problems with this data format. It returns sometimes wrong results. I suppose you know the examles when this happens so that I don't need to mention them. One solution would be to replace the doubles everythere with BigDecimal. To m, this seems to exagerrated because double values trouble ...