Click here to Skip to main content
15,887,776 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Rounding double value Pin
Nelek25-Sep-07 20:50
protectorNelek25-Sep-07 20:50 
GeneralRe: Rounding double value Pin
KASR125-Sep-07 20:54
KASR125-Sep-07 20:54 
GeneralRe: Rounding double value Pin
megha_gharote25-Sep-07 20:58
megha_gharote25-Sep-07 20:58 
GeneralRe: Rounding double value Pin
Cedric Moonen25-Sep-07 21:16
Cedric Moonen25-Sep-07 21:16 
GeneralRe: Rounding double value Pin
Cedric Moonen25-Sep-07 21:02
Cedric Moonen25-Sep-07 21:02 
GeneralRe: Rounding double value Pin
Stephen Hewitt25-Sep-07 21:17
Stephen Hewitt25-Sep-07 21:17 
GeneralRe: Rounding double value Pin
Nelek25-Sep-07 21:54
protectorNelek25-Sep-07 21:54 
AnswerRe: Rounding double value Pin
Cedric Moonen25-Sep-07 20:55
Cedric Moonen25-Sep-07 20:55 
In general, rounding is needed when you want to display the number as a string. Is that the case for you ?
If yes, you can use sprintf and specify a precision:
char szBuff[25];<br />
sprintf(szBuff,"%.2f",yourDouble);


This tells sprintf to print 2 decimals after the floating point.

If you need to use it as a double (and not a string), you can multiply it by 100, convert it to an int and divided it back by 100.0:
double yourDouble = 0.00922307;<br />
int yourInt = yourDouble * 100;<br />
double roundedDouble = yourInt / 100.0;


(you must be carefull and divide by 100.0, not by 100, otherwise the you will end up with an integer and not a double).


Cédric Moonen
Software developer

Charting control [v1.2]

GeneralRe: Rounding double value Pin
KASR125-Sep-07 21:03
KASR125-Sep-07 21:03 
GeneralRe: Rounding double value Pin
Nishad S25-Sep-07 21:09
Nishad S25-Sep-07 21:09 
GeneralRe: Rounding double value Pin
Cedric Moonen25-Sep-07 21:13
Cedric Moonen25-Sep-07 21:13 
AnswerRe: Rounding double value [modified] Pin
Nelek25-Sep-07 21:51
protectorNelek25-Sep-07 21:51 
AnswerRe: Rounding double value Pin
beko25-Sep-07 23:57
beko25-Sep-07 23:57 
GeneralRe: Rounding double value Pin
KASR126-Sep-07 1:15
KASR126-Sep-07 1:15 
QuestionCan we post data on web site through VC++ application? Pin
megha_gharote25-Sep-07 20:42
megha_gharote25-Sep-07 20:42 
QuestionRe: Can we post data on web site through VC++ application? Pin
Hamid_RT25-Sep-07 21:02
Hamid_RT25-Sep-07 21:02 
AnswerRe: Can we post data on web site through VC++ application? Pin
megha_gharote25-Sep-07 21:04
megha_gharote25-Sep-07 21:04 
GeneralRe: Can we post data on web site through VC++ application? Pin
Hamid_RT25-Sep-07 21:25
Hamid_RT25-Sep-07 21:25 
AnswerRe: Can we post data on web site through VC++ application? Pin
Naveen25-Sep-07 21:18
Naveen25-Sep-07 21:18 
QuestionNeed msgrua.h and msgruaid.h files Pin
Rahul Vaishnav25-Sep-07 20:34
Rahul Vaishnav25-Sep-07 20:34 
AnswerRe: Need msgrua.h and msgruaid.h files Pin
toxcct25-Sep-07 21:05
toxcct25-Sep-07 21:05 
GeneralRe: Need msgrua.h and msgruaid.h files Pin
Rahul Vaishnav26-Sep-07 0:00
Rahul Vaishnav26-Sep-07 0:00 
QuestionUninstaller Pin
yadahav25-Sep-07 19:39
yadahav25-Sep-07 19:39 
AnswerRe: Uninstaller Pin
Hamid_RT25-Sep-07 20:25
Hamid_RT25-Sep-07 20:25 
QuestionActivex mfc - urgent pls Pin
deeps_cute25-Sep-07 18:37
deeps_cute25-Sep-07 18:37 

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.