Formating Scientific Notation Output

This is a discussion on Formating Scientific Notation Output within the C Programming forums, part of the General Programming Boards category; Hi, Is there a way to format a double in a specific scientific notation form double d=123456789; printf(buf, "%+10.9E", d) ...

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

    Formating Scientific Notation Output

    Hi,
    Is there a way to format a double in a specific scientific notation form

    double d=123456789;

    printf(buf, "%+10.9E", d)

    results in +1.23456789+08E

    How could I get a result to be

    +0.123456789+09E (zero based)

    or

    +1.23456780+9E

    or

    +1.23456789+009E

    Thanks for any help!!!
    Is this done any easier in C++?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I don't know if something like this would be of any help:
    http://groups.google.com/group/comp....a68db750233ce7
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    You could probably cook something up with sprintf() and some string manipulation to reposition the decimal point and reformat the exponent.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 09:08 PM
  2. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 05:02 PM
  3. Control different DA output value!
    By Hunterhunter in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-13-2003, 11:11 AM
  4. Formatting Scientific Notation output
    By mashley in forum C Programming
    Replies: 5
    Last Post: 02-10-2003, 11:30 AM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 04:27 AM

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