outputing text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neel

    outputing text

    Hi,
    I want to print most significant digit of a number

    eg. if its 1.234455666, I want to print 1.23445
    if it is 123.123456, I want to print 123.123

    I tried using printf("%6f",va lue); but it means placing 6 digit of
    decimal value.

    I want to have total of 6 digits only.
    how do I do this?

    Thanks
  • MisterE

    #2
    Re: outputing text

    Neel wrote:
    Hi,
    I want to print most significant digit of a number
    >
    eg. if its 1.234455666, I want to print 1.23445
    if it is 123.123456, I want to print 123.123
    >
    I tried using printf("%6f",va lue); but it means placing 6 digit of
    decimal value.
    >
    I want to have total of 6 digits only.
    how do I do this?
    >
    Thanks
    You want to do printf("%6g",va lue);

    g is for double in scientific format (ie number of sig figs)

    Comment

    • MisterE

      #3
      Re: outputing text

      >
      You want to do printf("%6g",va lue);
      >
      g is for double in scientific format (ie number of sig figs)
      You might also want to look at this:


      I didn't know there were so many possibilities that were actually ANSI,
      wonder what C99 etc says about this

      Comment

      • James Kuyper

        #4
        Re: outputing text

        MisterE wrote:
        >
        >>
        >You want to do printf("%6g",va lue);
        >>
        >g is for double in scientific format (ie number of sig figs)
        >
        You might also want to look at this:

        >
        I didn't know there were so many possibilities that were actually ANSI,
        wonder what C99 etc says about this
        What that document refers to as the the "type" field is a combination of
        what C99 calls length modifiers and conversion specifiers.

        C99 adds the following length specifiers: hh (signed char) ll (long
        long), j (intmax_t), z (size_t), t (ptrdiff_t). When combined with
        conversion specifiers for unsigned types, the first three all refer to
        the corresponding unsigned type.

        C99 also adds two new conversion specifiers: a,A: hexadecimal floating point

        Comment

        Working...