Thread: float value

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    136

    float value

    hi all
    Code:
    #include <stdio.h>
    main()
    {
    float i,j=100.0,k=19456.0;
    i=j/k;
    printf(******** %f \n",i);
    }
    output is
    ******** 0.005139803

    i would like round figure it like
    0.005.

    how can i do this

    greetings munna

  2. #2
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    You can control the precision by trying something like : "&#37;.af" where 'a' is the number of digits following the decimal point.
    In the middle of difficulty, lies opportunity

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    also you should learn to use int main()
    and properly indent your code
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Looking at your code, I am guessing you must be using a compiler like TC or BC. Please switch over th GCC. It will help you in the long run.
    In the middle of difficulty, lies opportunity

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    136
    Quote Originally Posted by kris.c View Post
    You can control the precision by trying something like : "%.af" where 'a' is the number of digits following the decimal point.
    sorry. it is not working..

  6. #6
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Ofcourse it does,
    Code:
     # include<stdio.h>
    int main()
    {
            float i,j=100.0,k=19456.0;
            i=j/k;
            printf("******** &#37;.3f \n",i);
            printf("******** %.5f \n",i);
    return 0;
    }

    my output:
    Code:
    ******** 0.005
    ******** 0.00514
    In the middle of difficulty, lies opportunity

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by kris.c View Post
    Looking at your code, I am guessing you must be using a compiler like TC or BC. Please switch over th GCC. It will help you in the long run.
    What the heck leads you to guess that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 03:25 PM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM