Click here to Skip to main content
15,895,462 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CreateThread with more than one parameter Pin
eusto19-Jun-10 1:15
eusto19-Jun-10 1:15 
GeneralRe: CreateThread with more than one parameter Pin
Code-o-mat19-Jun-10 0:39
Code-o-mat19-Jun-10 0:39 
QuestionRuntime Error Pin
T.RATHA KRISHNAN18-Jun-10 20:12
T.RATHA KRISHNAN18-Jun-10 20:12 
AnswerRe: Runtime Error Pin
Garth J Lancaster18-Jun-10 21:59
professionalGarth J Lancaster18-Jun-10 21:59 
AnswerRe: Runtime Error Pin
Aescleal19-Jun-10 1:09
Aescleal19-Jun-10 1:09 
Questionhow to creat a soft environment of android system? Pin
VSVC18-Jun-10 16:06
VSVC18-Jun-10 16:06 
Questionrounding doubles to set # decimal places Pin
b-rad31118-Jun-10 8:33
b-rad31118-Jun-10 8:33 
AnswerRe: rounding doubles to set # decimal places [modified] Pin
Aescleal18-Jun-10 9:18
Aescleal18-Jun-10 9:18 
I don't do a lot of numeric stuff anymore so take this with a pinch of salt.

First off I don't know any C++ standard library facilities that would help. C had floor and ceil which take doubles and return an integer either truncating the value or rounding up to the next highest number. With these and pow you can write something that'll be good enough for most things.

Off the top of my head it'd look like:

double round_to( double number, unsigned number_of_decimal_places )
{
    double exponent( pow( 10, number_of_decimal_places ) );
    number *= exponent;   // disaster line!
    number += 0.5;
    return floor( number ) / exponent;
}

which is a bit cheesy - it won't work for negative numbers or any number that causes the line with the "disaster line!" comment to overflow an integer. However they might give you a handle if no one comes up with a better idea!

Cheers,

Ash

Edited to remove a spurious brace...

modified on Friday, June 18, 2010 3:52 PM

GeneralRe: rounding doubles to set # decimal places Pin
b-rad31118-Jun-10 9:31
b-rad31118-Jun-10 9:31 
AnswerRe: rounding doubles to set # decimal places Pin
CPallini18-Jun-10 9:20
mveCPallini18-Jun-10 9:20 
GeneralRe: rounding doubles to set # decimal places Pin
b-rad31118-Jun-10 9:31
b-rad31118-Jun-10 9:31 
GeneralRe: rounding doubles to set # decimal places Pin
CPallini18-Jun-10 9:42
mveCPallini18-Jun-10 9:42 
QuestionWhere do I write user data in Win7? Pin
Koolski18-Jun-10 7:34
Koolski18-Jun-10 7:34 
AnswerRe: Where do I write user data in Win7? Pin
Code-o-mat18-Jun-10 8:29
Code-o-mat18-Jun-10 8:29 
GeneralRe: Where do I write user data in Win7? Pin
Koolski18-Jun-10 9:31
Koolski18-Jun-10 9:31 
AnswerRe: Where do I write user data in Win7? Pin
Maximilien18-Jun-10 8:35
Maximilien18-Jun-10 8:35 
GeneralRe: Where do I write user data in Win7? Pin
Koolski18-Jun-10 9:30
Koolski18-Jun-10 9:30 
GeneralRe: Where do I write user data in Win7? Pin
Code-o-mat18-Jun-10 9:46
Code-o-mat18-Jun-10 9:46 
GeneralRe: Where do I write user data in Win7? Pin
krmed18-Jun-10 10:35
krmed18-Jun-10 10:35 
AnswerRe: Where do I write user data in Win7? [edited] Pin
Ravi Bhavnani18-Jun-10 13:52
professionalRavi Bhavnani18-Jun-10 13:52 
QuestionUpgrade to VS2010 Compiler error (atlbase.h) Pin
Maximilien18-Jun-10 4:55
Maximilien18-Jun-10 4:55 
AnswerRe: Upgrade to VS2010 Compiler error (atlbase.h) Pin
Aescleal18-Jun-10 6:46
Aescleal18-Jun-10 6:46 
QuestionHow to develop a visual studio plugin to hook debugging? Pin
kcynic18-Jun-10 4:51
kcynic18-Jun-10 4:51 
AnswerRe: How to develop a visual studio plugin to hook debugging? Pin
VSVC18-Jun-10 16:00
VSVC18-Jun-10 16:00 
QuestionAssertion when Deleting the View in Splitter Window. Pin
janaswamy uday18-Jun-10 3:10
janaswamy uday18-Jun-10 3:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.