formatting question..

This is a discussion on formatting question.. within the C++ Programming forums, part of the General Programming Boards category; if you have an int, say 34 and you want it to print out .000034 (withouit it saying 3.4e-6). What ...

  1. #1
    Unregistered
    Guest

    Question formatting question..

    if you have an int, say 34 and you want it to print out .000034 (withouit it saying 3.4e-6). What do you do?

    Also, is there a way to print 000034 without the decimal?


    thanks for your time people

  2. #2
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    for a standard amount of 0s

    Code:
    #include <iostream.h>
    #include <stdio.h>
    int main()
    {
     int x = 34;
     cout<<".0000"<<x;
     getchar();
     return 0;
    }
    for a non- standard, use a int and a loop.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Question Hmm

    Is this what you mean?
    Code:
    
    int iVar=34;
    printf("%f", ((float)iVar/1000000));
    
    When you say "without the decimal", do you mean "without the dot"? 0.000034 without the decimal would be 0
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Unregistered
    Guest
    Thanks for your help guys.

    To clarify, I mean't with leading zeros without the dot. (000034).

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    you can use ostream manipulators and flags like setw() and fill() to create 00034 from 34. They should be explained in your C++ text or in you compilers help section.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  3. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21