Thread: Printf float printing

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    1

    Printf float printing

    Is it possible to make printf print float values like 5.301 and 2.01 without printing extra zeros on the end?

    Thanks.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    What's wrong with %f? it does not print zeroes at the end.

    Be more specific what you want to get
    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

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    11
    printf( "%.2f", .650 );

    will print .65 substitute the 2 with 3 or however many digits you want. Keep in mind that it will always be that many digits.

    So,

    printf( "%.2f", .656 );

    will print .66

    Not sure if there's a way to make it expand.

    //The OPs statement does print zeros on my machine.
    glibc version 2.6.1
    Last edited by krock923; 12-08-2007 at 12:42 AM.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems reading entered race times C
    By loopymoo26 in forum C Programming
    Replies: 12
    Last Post: 05-23-2009, 07:38 AM
  2. segmentation fault upon reload
    By yabud in forum C Programming
    Replies: 8
    Last Post: 12-18-2006, 06:54 AM
  3. help me
    By warthog89 in forum C Programming
    Replies: 11
    Last Post: 09-30-2006, 08:17 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Azbia - a simple RPG game code
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 05-03-2002, 06:59 PM