DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Problem with float data type

  1. #1
    Join Date
    Jan 2008
    Posts
    4

    Question Problem with float data type

    hi.....

    I am a beginner in C++ and I been trying programmed a very simple program...
    this is all about float data type....

    the program goes like this:

    float result;
    result = 5/9;
    printf("%.2lf",result);

    output : 0.00

    why is it the output is not 0.55????
    do you have any solution???how???

    thanks for any answer......:WAVE:

    ____________________________________
    http://michael1234539.blogspot.com
    http://www.outsourceit2philippines.com

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    make at least one of your numbers a floating point number - 5.0 or 9.0 - to snap your compiler out of "integer division" which will occur since both 5 and 9 are integers, which will truncate your result to the floor of the result (0) rather than the "floating point division" which will give you 0.55

Similar Threads

  1. Replies: 0
    Last Post: 01-29-2007, 12:34 AM
  2. Replies: 1
    Last Post: 07-25-2002, 06:06 PM
  3. Replies: 1
    Last Post: 06-10-2002, 11:10 AM
  4. Replies: 0
    Last Post: 11-15-2001, 11:26 AM
  5. What is the UDT?
    By Tahui in forum VB Classic
    Replies: 2
    Last Post: 11-22-2000, 11:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center