Click here to Skip to main content
15,920,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionon right click new option for any file or folder Pin
amaneet29-Sep-06 21:39
amaneet29-Sep-06 21:39 
AnswerRe: on right click new option for any file or folder Pin
Dominik Reichl30-Sep-06 1:06
Dominik Reichl30-Sep-06 1:06 
AnswerRe: on right click new option for any file or folder Pin
Hamid_RT2-Oct-06 8:59
Hamid_RT2-Oct-06 8:59 
QuestionHow do you round a float variable in C++ [modified] Pin
BlitzPackage29-Sep-06 18:48
BlitzPackage29-Sep-06 18:48 
AnswerRe: How do you round a float variable in C++ Pin
ShilpiP29-Sep-06 19:14
ShilpiP29-Sep-06 19:14 
GeneralRe: How do you round a float variable in C++ Pin
amaneet29-Sep-06 21:42
amaneet29-Sep-06 21:42 
GeneralRe: How do you round a float variable in C++ Pin
ShilpiP29-Sep-06 23:14
ShilpiP29-Sep-06 23:14 
GeneralRe: How do you round a float variable in C++ Pin
Stephen Hewitt30-Sep-06 2:27
Stephen Hewitt30-Sep-06 2:27 
First you have to decide what kind of rounding you’re after. There are four common ways rounding can be performed:
 - Towards +ve infinity.
 - Towards -ve infinity.
 - Towards 0.
 - Away from 0.

Towards +ve infinity:
In this mode we choose the closest number that’s higher. For example, if rounding to the nearest integer:
1.6 -> 2
-1.6 -> -1

Towards -ve infinity:
In this mode we choose the closest number that’s lower. For example, if rounding to the nearest integer:
1.6 -> 1
-1.6 -> -2

Towards 0:
In this mode we chose the closet number in the direction of zero. For example, if rounding to the nearest integer:
1.6 -> 1
-1.6 -> -1

Towards 0:
In this mode we chose the closet number in the direction away from zero. For example, if rounding to the nearest integer:
1.6 -> 2
-1.6 -> -2

For simplicity I’ll only consider the “Towards +ve infinity” mode. If you want to round a double or float to the closest integer code like this will do it:
int n = double_val+0.5;

To a double to the nearest tenth:
double n = floor(double_val*10.0+0.5)/10.0;

To a double to the nearest hundredth:
double n = floor(double_val*100.0+0.5)/100.0;

Steve

GeneralRe: How do you round a float variable in C++ Pin
Hamid_RT2-Oct-06 9:02
Hamid_RT2-Oct-06 9:02 
AnswerRe: How do you round a float variable in C++ Pin
Eytukan30-Sep-06 7:32
Eytukan30-Sep-06 7:32 
AnswerRe: How do you round a float variable in C++ Pin
BlitzPackage30-Sep-06 10:05
BlitzPackage30-Sep-06 10:05 
GeneralRe: How do you round a float variable in C++ Pin
markkuk30-Sep-06 12:52
markkuk30-Sep-06 12:52 
GeneralRe: How do you round a float variable in C++ Pin
BlitzPackage30-Sep-06 13:36
BlitzPackage30-Sep-06 13:36 
GeneralRe: How do you round a float variable in C++ Pin
Stephen Hewitt30-Sep-06 16:04
Stephen Hewitt30-Sep-06 16:04 
GeneralRe: How do you round a float variable in C++ Pin
BlitzPackage30-Sep-06 19:11
BlitzPackage30-Sep-06 19:11 
QuestionReturn an Object By Value Pin
BlitzPackage29-Sep-06 17:23
BlitzPackage29-Sep-06 17:23 
AnswerRe: Return an Object By Value Pin
Mike_V29-Sep-06 17:36
Mike_V29-Sep-06 17:36 
GeneralRe: Return an Object By Value Pin
BlitzPackage29-Sep-06 17:43
BlitzPackage29-Sep-06 17:43 
GeneralRe: Return an Object By Value Pin
Mike_V29-Sep-06 17:59
Mike_V29-Sep-06 17:59 
GeneralRe: Return an Object By Value Pin
BlitzPackage29-Sep-06 18:04
BlitzPackage29-Sep-06 18:04 
AnswerRe: Return an Object By Value Pin
Anonymuos29-Sep-06 23:01
Anonymuos29-Sep-06 23:01 
AnswerRe: Return an Object By Value Pin
bob1697230-Sep-06 5:55
bob1697230-Sep-06 5:55 
QuestionFinding Your Own Responses Back Pin
Bram van Kampen29-Sep-06 16:39
Bram van Kampen29-Sep-06 16:39 
QuestionNotification of unhecking the checkbox inside the DateTimeCtrl... Pin
tamasan29-Sep-06 16:29
tamasan29-Sep-06 16:29 
AnswerRe: Notification of unhecking the checkbox inside the DateTimeCtrl... Pin
ShilpiP29-Sep-06 19:34
ShilpiP29-Sep-06 19:34 

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.