Thread: setprecision() - can I count on it rounding or not?

  1. #1
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787

    setprecision() - can I count on it rounding or not?

    okay, so here's the story: Back in my high school programming classes, we were told that iomanip didn't round. In my college classes, whenever we needed to round, we did it on our own.

    Then somebody on these boards told me it did round, so I took a closer look at it and found out that it did round. Then in an IRC channel, somebody asked if it rounded, and somebody replied saying that it was locale specific, and not to rely on it rounding.

    I tried checking the standard, and couldn't make any real sense out of what they said about it, and all of the explanations I could find about setprecision said something along the lines of "Sets the number of digits of precision".

    so my question is this: Can I depend on setprecision to round numbers all the time?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    6
    hi ....

    can you try this link:

    http://www.cplusplus.com/ref/iostrea...precision.html

    cio

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ...I read that already... all it says is:
    The precision determines the maximum number of digits that shall be output on insertion operations to express floating-point values, counting both the digits before and after the decimal point.
    but that doesn't say anything about rouding at all... they show you in their example that it rounds, but that's the only place, and it's shady at that.

    edit: the answer may lie in the definition of the word precision itself...

    Quote Originally Posted by The American HeritageŽ Dictionary of the English Language, Fourth Edition
    The number of significant digits to which a value has been reliably measured.
    Quote Originally Posted by wiktionary
    (mathematics) the number of significant digits to which a value may be measured reliably
    but then I guess that kinda leaves it up to interpretation... but I'm still wondering if I'm missing anything in the standard that says it should round a number...
    Last edited by major_small; 11-23-2005 at 02:52 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bintree and count (withouth using template)?
    By cubimongoloid in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2009, 06:22 AM
  2. input question
    By piyush_v in forum C Programming
    Replies: 9
    Last Post: 04-12-2007, 07:09 AM
  3. I'm missing something obvious
    By crash88 in forum C Programming
    Replies: 7
    Last Post: 07-02-2006, 12:51 AM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. count only lines of code...
    By flightsimdude in forum C Programming
    Replies: 13
    Last Post: 09-23-2003, 07:08 PM