Double/float/BigDecimal

Hi all
What is the major difference between
double, float, BigDecimal inorder to use for
the accurate results in currency calculations.
Thanks in advance.

double and float are basically the same, other than double is twice as large. They are not accurate. I belive that (you can test this yourself) if you:
<code>
double d = .001 + .001 + .001 + .001;
System.out.println(d == 0);
</code>
you get true. at least something similar to above shows this.
BigDecimal is incredibly large and it is accurate.

Similar Messages

  • Double Float Margin Bug "error"

    I did a browser compatibility check on one of the pages that
    I am building and got this error.............
    "Line 112, Double Float Margin Bug 'error'
    When a margin is applied to a floated box on the same side as
    the direction of the float, the margin is doubled. This bug only
    affects the first float in a row of one or more floats.
    Affects: Internet Explorer 6.0
    Likelihood: Very Likely"
    I have many thumbnails for a gallery page in their own divs,
    within the content div, and they are floated in there.
    When I viewed solutions, they suggested:
    "When a margin is applied to a floated box on the same side
    as the direction the box is floated AND the floated box is the
    first one inside its containing box, the margin is doubled. (In
    other words, a left-floated box with margin-left set to move it
    away from its containing box will be twice as far away from the
    left edge of the containing box as intended.)
    SOLUTION
    Specify display: inline; for the affected float.
    DETAILED DESCRIPTION
    This bug only reproduces when the floated element's margin
    extends in the same direction as the float itself, and is between
    the float and the container box's inside edge. Subsequent floats
    with similar margins won't reproduce this bug- just the first float
    in any row of floated elements."
    Does anyone have any solutions, suggestions as how to fix
    this? I will attach my code. And if anyone has a better solution as
    to laying my thumbnail divs in another div container, please say
    so. The reason I am putting them in separate divs is because that
    is what someone suggested to use them with Lightbox2. He said they
    needed some kind of special CSS to enable some of the functions and
    they (the thumbnails) were easier to style if they were in their
    own separate divs. I'm open for any suggestions.
    Thanks!

    Just add "display:inline" to the styling like this:
    .image {
    background-color: #121922;
    height: 100px;
    width: 100px;
    float: left;
    margin: 20px;
    display: inline;
    }

  • How to convert value from exp. value to double/float???

    Hi all,
    I am fetching values from database, which is of type double / float.
    eg. values will be like -22,777,548 will be stored in database.
    NOw if i use
    float a= rs.getFloat(1);
    out.println("a="+a);
    I get output as a= -2.2777548E7
    I want to remove "E" from out put value and display as it was given in DB.
    How to solve this problem?
    Please Help!
    Regards
    Ashvini

    What do you mean - 'how does it work' ? All format classes (MessageFormat, DecimalFormat , SimpleDateFormat etc) are used to convert data from one form to other. Go through the java.text.* api. They work based on some pattern searches, pattern matches etc - dont know in detail :)
    As for the other things, thanks :)
    cheers,
    ram.

  • SQL*loader support database columns Of Binary Double/Float

    Does SQL*loader support database columns Of Binary Double/Float when applying Direct Path?

    Why not use Google and find out for yourself.
    The first hit on Google is this
    Go see for yourself
    Regards
    FJ

  • Failure to convert infinite double to BigDecimal

    I need to convert double to BigDecimal. But one of the double values is infinite and is not converted into the BigDecimal.
    I am getting this error.
    java.lang.NumberFormatException: Infinite or NaN.
    This is how I am converting it.
    private BigDecimal convert(Double object) {
    return new BigDecimal(object);
    Does anybody know how to do this?
    Thanks.

    caesarkim1 wrote:
    It seems to me that BigDecimal can't handle infinite number.Correct. As per the documentation in BigDecimal(double) and BigDecimal(String)
    BigDecimal(double)
    Throws: NumberFormatException - if val is infinite or NaN.
    BigDecimal(String)Translates the string representation of a BigDecimal into a BigDecimal. The string representation consists of an optional sign, '+' ('\u002B') or '-' ('\u002D'), followed by a sequence of zero or more decimal digits ("the integer"), optionally followed by a fraction, optionally followed by an exponent
    Throws: NumberFormatException - if val is not a valid representation of a BigDecimal

  • Double - Float casting or Why isn't there float sqrt?

    Is there any reason why not to include float sqrt? I'm pretty pissed since, it is just... well plain stupid. I hope it can be added, not to mention that casting takes away performance, not much, but I have to do a lot of casting since I'm doing 3d grahpics... Anyone know any solluions? Is there any point going the hard way and implementing own sqrt for float?
    WHY WHY WHY, OH WHY.
    Something is rotten in the state of java.

    The absence of Math.sqrt(float) and float versions of other relevant methods is apparently becuase early versions of the Java compiler could not distinguish overloaded methods which only differed in double/float parameters. The current compilers do not have this problem and it has been proposed that the extra methods should be added but I don't know when this might happen.
    In any case how sure are you that casting between double and float is causing any significant performance problem? This cast is NOT particularly expensive (casting to 'int' from float or double is usually much more expensive).
    What processor are you using --- as far as I know Intel processors do not give any speed benefit from doing sqrt on float instead of double. I believe that many RISC processors do benefit from using float where possible.

  • A problem using doubles/floats

    i have an applet with 4 radio buttons and 5 check boxes! when i click on some (mix and match) the value on the text field sometimes goes like this 8.8888889 etc, and other times it is like 2.34! how can i change that 8.88889 to be displayed as 2.34! i have tried changing the value in the code, but that solves the problem but then a diff combination does the same thing! :(

    But anyway, since we're in this thread now...
    The short version is that there are a finite number of values that can be stored in a float or double, but there are infinitely many float/double values in the real numbers in the range between he min value and max value. So a lot of numbers are going to be aproximations.
    Why is a "simple" number like, say, 0.9, not exact, you ask? Java's VM (and pretty much all modern computer hardware) stores floating point number in base-2, not base ten. So if you look at the bits, and you see "1" in the first position after where the binary-point (base-2 equivalent of a decimal point) would be, that doesn't mean 1/10, it means1/2. So "0.5" in decimal (base-10) is the same as "0.1" in binary (base-2). What's "0.1" base-10 in base-2? Don't know off the top of my head, but it's a repeating fraction, just like 0.3333333... for 1/3 (which, in base-3, is 0.1, exactly).
    For more details, see:
    http://docs.sun.com/source/806-3568/ncg_goldberg.html

  • Printing doubles/floats

    hi,
    i'm trying to convert a double (or float, either one) to a string and print it to the screen. i can't find a way to do it that maintains ALL of the digits in the number - at best, 15 or so digits after the dec point are kept and the rest cut off. i don't know the number's precision in advance - i just want to be able to capture the accurate number in a string, regardless of the precision.
    thanks,
    --vlb1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Then you can set DecimalFormat for the maximum possible range of digits after a decimal point and then once you have a String iterate through it backwards until you reach a non zero digit that will be you precise decimal precision.
    This whole solution is backwards - but today is Friday and my brain is a lot like Jello right now :)

  • Using double/floats for co ordinates?

    hi is it possible to use float/double values for the following code or simlar?
    g.drawImage(cards, 0.5, 0.8, this);
    does the drawimage on support ints?

    Update and demo: Am I the only one who is forever tweaking rendering hints
    to get the right effect? Anyhowdy, I think INTERPOLATION was the hint I needed
    to tweak to get subpixel shifting of images:
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class ShiftyExample extends JPanel {
        private BufferedImage image;
        private float delta;
        public ShiftyExample(BufferedImage image, float delta) {
            this.image = image;
            this.delta = delta;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g.create();
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g2.drawRenderedImage(image, null);
            g2.drawRenderedImage(image, AffineTransform.getTranslateInstance(delta, 0));
            g2.dispose();
        public static void main(String[] args) {
            EventQueue.invokeLater(new GuiBuilder());
        static class GuiBuilder implements Runnable {
            public void run() {
                BufferedImage image = createImage();
                JPanel cp = new JPanel(new GridLayout(1,0));
                cp.add(new ShiftyExample(image, 0f));
                cp.add(new ShiftyExample(image, 0.5f));
                cp.add(new ShiftyExample(image, 1f));
                cp.add(new ShiftyExample(image, 1.5f));
                cp.add(new ShiftyExample(image, 2f));
                JFrame f = new JFrame("ShiftyExample");
                f.setContentPane(cp);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.setSize(300,200);
                f.setLocationRelativeTo(null);
                f.setVisible(true);
            BufferedImage createImage() {
                BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
                Graphics2D g = image.createGraphics();
                g.setColor(Color.BLACK);
                g.drawLine(10,0,10,100);
                g.dispose();
                return image;
    }Explanation: the image is a vertical black line on a clear background.
    What you see on the frame are five versions of the image displayed
    against a shifted copy of itself, shift 0, 0.5, 1, 1.5 and 2 units. If you really stare at the
    fractional examples, you will see gray pixels being used instead of just black
    and white. Woop-de-doo...

  • Double or BigDecimal

    Is there a way we can map the NUMBER field to BigDecimal than Double like in other systems.
    I am trying to port our entire system from JDBC based calls to Toplink 9.0.3 so there are already a lot of objects using BigDecimal that i dont want to change the behaviour of.
    Thanks,
    Galoch

    If you have an attribute of type BigDecimal that maps with a Direct to field on a column in the database of type NUMBER, it should just work.
    - Don

  • Double/float displaying ???

    Hi,
    I get the content of a field and stores it in a double or float variable. If this value is greater than 10 000 000, it automatically appears as 1E7 if I display it again.
    My question is:" Is there a way to display a float or double value without this number format ???"
    Thanks in advance, Frederic.

    This problem can be solved easily.
    You can use NumberFormat which is the abstract base class for all number formats. It basically provides the interface for formatting and parsing numbers.
    Below is a simple example of how it works. I hope you find it useful.
    import java.text.*;
    class doubles {
         public static void main(String args[]) {
              double myDouble = 1000000000;
              NumberFormat nf = NumberFormat.getNumberInstance();
              //this is how it would appear without the number formatting.
              System.out.println(myDouble);
              //this is after we use the new number format.
              System.out.println(nf.format(myDouble));
    Hope this helps.
    Kind Regards.
    P.S.
    If you require further assistance, feel free to email me.
    [email protected]
    fdm Group
    Brighton
    United Kingdom

  • Help! Expand Box, Doubled Float Margin Bug & Float Drop Problem

    Hi,
    My website has a title problem in line 159, 161 and 164, and I couldn't fiugre out why since my design view is TOTALL messed up in dreamweaver. However, by using google chrome broswer, webpage is still displaying fine, but not IE or firefox.. I was wondering if someone can help me take a look and give me some feedback how to fix the issue....thank you very much,
    http://www.akuiskitchen.com/

    Thank you, all errors have been fixed from w3 validation site, but I still have browser compability problem..
    Ken, do you mean removing all below underline portion under demostyle.css?
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Unable to load page</title>
    <style type="text/css">
    #container {
              width: 50%;
              margin: 3em auto;
              font-family: Verdana, Geneva, sans-serif;
    #dwicon {
              float: left;
              margin-right: 2em;
    #error {
              padding-top: .5em;
    #desc {
    </style>
    </head>
    <body>
    <div id="container"> <img id="dwicon" src="dw://configuration/Shared/ICE/Images/warning_icon.gif" width="32" height="32" alt="Warning" />
      <h3 id="error">Server Not Found</h3>
      <p id="desc">The page "http://localhost/resources/demos/style.css" was not loaded because Dreamweaver could not find the server "localhost". Please make sure you are connected to the internet and the server name is correct.</p>
    </div>
    </body>
    </html>

  • JSpinner and BigDecimal , what am i doing wrong?

    hi,
    i'm trying to use a JSpinner to let the user input currencies.
    all my currencies are represented by BigDecimals.
    SpinnerNumberModel provides the following methodn which let's me think i can use BigDecimals in the spinner component:
    setStepSize(Number stepSize)
    The following code fails though :
    JSpinner spinner = new JSpinner();
    SpinnerNumberModel model = new SpinnerNumberModel();
    model.setStepSize(new BigDecimal("0.01");
    model.setValue(new BigDecimal("0.00");
    spinner.setModel(model);the spinner arrows don't work , and any value i enter is rejected
    what could be the problem ?

    From the SpinnerNumberModel API documentation:
    Internally, there's only support for values whose type is one of the primitive Number types: Double, Float, Long, Integer, Short, or Byte.

  • How to make floating point division

    I have tried many alternatives but i couldnt make any single floating point number printed to a page...
    I am compiling the servlet with eclipse 3.2 without any error but the jsp page says      java.lang.NoSuchFieldError: floatnumber even i have that variable...
    i have tried double,float but both of them makes the error above...but i can print long as well.
    can anyone teach me to divide 2 integer values and print the exact result like;
    3 / 5 = 0.6

    can anyone teach me to divide 2 integer values and
    print the exact result like;
    3 / 5 = 0.6
    int a= 3, b= 5;
    double result= ((double)a)/b;... or any valid variation thereof.
    kind regards,
    Jos

  • Floating Point Arithmatic Error

    Hi,
    I know actionscript represents numbers and double precision
    floating point values. I'm having a problem where double arithmatic
    in actionscript doesn't match the results of the same double
    arithmatic in C++ / C#.
    EXAMPLE:
    In C++ / C#:
    double x, y, x1, y1;
    x = 209.4;
    y = 148.8;
    x1 = 203.0;
    y1 = 145.0;
    double ddx = x - x1;
    double ddy = y - y1;
    RESULT
    ddx: 6.4000000000000057
    ddy: 3.8000000000000114
    In Flash ActionScipt 2:
    var x, y, x1, y1;
    x = 209.4;
    y = 148.8;
    x1 = 203.0;
    y1 = 145.0;
    var ddx = x - x1;
    var ddy = y - y1;
    RESULT
    ddx: 6.39999999999992
    ddy: 3.80000000000024
    After researching Flash / Actionscript "var" stores numerical
    values as doubles ( 8 bytes ) just like doubles are stored in C++ /
    C# ( 8 bytes ). Why would there be a difference between the results
    of ddx and ddy? Are there different implementations of double
    floating point math? If so, Is there a way I can mimic the Flash /
    Actionscript version in C++ / C#?
    Any help would be great!
    Thanks!

    Hmmm, so you're saying the actual binary representation is
    the same but they're just displayed differently?

Maybe you are looking for