Re: double with precision



On Wed, 27 Jun 2007 23:25:16 +0100, Roy Gourgi <royng@xxxxxxxxxxxx> wrote:

Thanks Eric,

Just out of curiosity why can't the number 1.74 be represented exactly with
a double?

http://www2.hursley.ibm.com/decimal/decifaq1.html#inexact

The solution, in Java, is to use BigDecimal (http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html) instead of double, but that can make your code quite clunky. An alternative is to multiply all of your values by 100 so that you are never dealing with fractions (except when you convert them for display).

Dan.

--
Daniel Dyer
http//www.uncommons.org
.



Relevant Pages

  • Re: Simple 2d graphing in web page - where to begin
    ... a time display of the cursor position as it is moved over the image. ... Java noob question: what /type/ of Java would I need? ... would have a server or servlet application that access the database, ... that renders the graphs. ...
    (comp.lang.java.programmer)
  • Re: Java V6 install problem
    ... export the path and display ... # echo $DISPLAY ... Could not create the Java virtual machine. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: Help with Threads (wait and notify)
    ... > Since i am writing visualization applets for graph algorithms i don't ... > display ONLY one NODE every time user clicks on step button ... http://uio.dev.java.net Unified I/O for Java ...
    (comp.lang.java.gui)
  • Java Problems on Multiheaded Workstations
    ... We recently configured a workstation with six heads as three virtual screens using twinview. ... The java programs all open their displays on:0.0, no matter what the DISPLAY variable is set to. ... it opens its display on:0.0. ...
    (RedHat)
  • [Help Please] Graphics programming problem.
    ... display image1 ... wait until image1 is drawn to the screen ... What happens is that Java ... PokerDice.java cannot resolve symbol ...
    (comp.lang.java)