Thread: Quick decimal question

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    81

    Quick decimal question

    i'm using tomething like this

    sprintf(buffer,"Number: %.5f",int);

    i want it to always be the right number so if i had 5.23 i don't want it showing up as 5.23000 or i fi had a number like 5.1234567 i want all the numbers to show, is there something i can do to hav the decimal point always set itself to the proper number of places?

  2. #2
    Shadow12345
    Guest
    I am pretty sure that the most decimal places you can achieve is 5 places by using a double or float;
    Last edited by Shadow12345; 09-30-2002 at 05:17 PM.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    How many decimal places does a recuring number have? For example 1/3.

    Anyway, lookup the %g modifier, that may do what you want.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Are you using printf() in a C++ program? In C++, you could format cout using setf() and setprecision().

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM