Printf float printing

This is a discussion on Printf float printing within the C Programming forums, part of the General Programming Boards category; Is it possible to make printf print float values like 5.301 and 2.01 without printing extra zeros on the end? ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    What's wrong with %f? it does not print zeroes at the end.

    Be more specific what you want to get
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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-07-2007 at 11:42 PM.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,182
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

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, 05: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

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