Thread: loss of signifigant digits

  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,263
    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,263
    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, 12:55 PM
  2. reverse a number digits
    By tootoo in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2007, 11:24 AM
  3. Counting letters and digits
    By FeNCinGeR in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2006, 11:39 AM
  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, 11:43 AM