Thread: printf trying to format numbers....

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    2

    printf trying to format numbers....

    Hi,

    I think this explains what I'm trying to do:
    Code:
    for(i=0;i<5;i++) {
    		printf("float j=%%d.%df\n",i,i,j);
    	}
    I don't wish to hard code the way of formatting a float, but what I've got doesn't work, any solutions to this???

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    what is it you want it to do?

    what are i j?

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You mean something like...:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
      int i;
    
      for(i = 0;i < 5;++i)
        printf("&#37;*.*f\n", i, i, 1.5f);
    
      return 0;
    }
    ?

    My output:
    Code:
    itsme@dreams:~/C$ ./varformat
    2
    1.5
    1.50
    1.500
    1.5000
    itsme@dreams:~/C$
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    2

    Smile Yes, thank you

    That's what I'm trying to do, thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. saying hello and 1st question
    By darksys in forum C Programming
    Replies: 12
    Last Post: 10-31-2008, 02:58 PM
  4. Whats Wrong Whith This!?
    By SmokingMonkey in forum C++ Programming
    Replies: 8
    Last Post: 06-01-2003, 09:42 PM
  5. Replies: 4
    Last Post: 04-01-2003, 12:49 AM