loss of signifigant digits

This is a discussion on loss of signifigant digits within the C++ Programming forums, part of the General Programming Boards category; I'm losing signifigant digits assigned to a "double" variable. Is there something I can do to keep them? For example, ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    Question loss of signifigant digits

    I'm losing signifigant digits assigned to a "double" variable. Is there something I can do to keep them?


    For example, when assigning double wavelength with the value of 1527.6051 the program returns wavelength's value as 1527.61.

    Do I need to use a different variable type to prevent the rounding?


    Wjahvces

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    what are you printing it with?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    I'm using cout <<.


    cin>> wavelength;
    cout<<"You entered wavelength: " << wavelength<<"\n";



    is what i'm using.

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    try this

    cin>> wavelength;
    cout.precision(6); // set the output precision to 6
    cout<<"You entered wavelength: " << wavelength<<"\n";
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    Thank You!

    6 didn't work but 8 did. that's what i was missing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. decimal to number if digits in different bases
    By jorgejags in forum C Programming
    Replies: 21
    Last Post: 09-24-2008, 01:55 PM
  2. reverse a number digits
    By tootoo in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2007, 12:24 PM
  3. Counting letters and digits
    By FeNCinGeR in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2006, 12:39 PM
  4. Hex digits stored in char array.
    By Kevinmun in forum C Programming
    Replies: 8
    Last Post: 11-18-2005, 04:05 PM
  5. Configurations give different results
    By Hubas in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 12:43 PM

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