Results 1 to 6 of 6

Thread: Scientific numbers

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    Scientific numbers

    Code:
    double var = 4894000000;
    cout<<var;
    This outputs 4.894e+009 for the value. How can I have it output 4894000000 instead?
    Alcohol & calculus don't mix.
    Never drink & derive.

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I guess you could break the number up into smaller number such as 48940 and 00000 then you won't get the errors and in a console you can't tell the difference

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    So there's no other way to do it?
    Alcohol & calculus don't mix.
    Never drink & derive.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try something like cout << setwidth(20) << dValue << endl;
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    jim mcnamara
    Guest
    Heresy:

    You CAN use stdio in console mode programs.

    PHP Code:
    #include <stdio.h>
    printf"my big number = %f\n", var);

    or
    char t[80];
    sprinf(t,"%f",var);
    printf("%s\n",t);

    or (
    non-ansi)

    Cstring str;
    str.format("%f",var);
    cout << str
    cout is not ansi c. C++ supports ansi c, almost mostly.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The reason cout isn't ANSI C is because it's ANSI C++

    You can use stdio, but there's no point if you're using iostreams, which you should be in C++ programs.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width