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

Number of digit

  1. Jul 6, 2010 #1
    Hello all,

    I wrote a C program to multiply a column of numbers (for eg., number will look like this 10.45618) with some constant...
    after multiplication i get the correct value (i tested using calculator).
    Now the output is 0.00005672 (i use %14.9lf) ..but i want them to display like this: 5.672E or D-5.
    E stands for 10.
    thanks for your help.
  2. jcsd
  3. Jul 6, 2010 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Check the documentation on format specifiers for printf. There are a lot of useful options, it would be good to know what's possible and know where to look things up -- so go googling!

    I think for your particular issue, you want 'e' or 'g' instead of 'f'; I don't remember which one.
  4. Jul 6, 2010 #3


    Staff: Mentor

    It's e. g uses the shorter of the e vs. f formats.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook