Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C: Format Specifier %f

  1. Jan 10, 2010 #1
    C: Format Specifier "%f"

    I understand the format specifier is a placeholder for a value to be calculated via scanf feature but I'm unsure of the notation %X.Yf
    What does the X represent? i understand Y gives the number of spots after the decimal but i don't understand what the X portion does? Can you give a few examples?
  2. jcsd
  3. Jan 10, 2010 #2


    User Avatar
    Science Advisor

    Re: C: Format Specifier "%f"

    Do you mean scanf, or printf?

    I don't like scanf, but that's a detail. In scanf, the Y doesn't mean anything; in fact I think it is an error to use .Y in a scanf format. The number of places is whatever you have in the input text.

    The field width (X) is the maximum number of characters it will read for that "field". The specifics of where fields start and finish can be a bit subtle. Basically the floating point field in the input text end when you get to a character which is not part of the number, of once you've run out of the allowed field width, whichever comes sooner.

    Cheers -- sylas
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook