• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Double Value Problem

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Why does the following program display the value for 'g' as 113.99999999999
instead of 114? The program works fine with all the values except for 113,114,115. Can any body tell me what is wrong? It gives problem when I try to multiply by 100.

public class doubleString{

public static void main(String[] args)
{
Double d = new Double(1.14);
double f = d.doubleValue();
System.out.println("f*100 = " + f);
double g= d.doubleValue()*100.0;
System.out.println("g ="+ g);
}

}
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
checkout these links
<http://en.wikipedia.org/wiki/Floating_point>; Floating point - From Wikipedia, the free encyclopedia
<http://java.sun.com/developer/JDCTechTips/2003/tt0204.html#2>; Some things you should know about floating-point arithmetic
<http://docs.sun.com/source/806-3568/ncg_goldberg.html>; What Every Computer Scientist Should Know About Floating-Point Arithmetic
 
Ajay Singh
Ranch Hand
Posts: 182
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic