Solved

Rounding off values

Posted on 1998-09-21
2
163 Views
Last Modified: 2010-04-01
CString cs;
float Dummy = 48;
Dummy = ((100*Dummy)/322);
cs.Format("Dummy = %f ",Dummy);
m_static1.SetWindowText(cs);

How do I round off the float Dummy to 2 decimal places and loose all evidence of the previous unrounded number.
0
Comment
Question by:rose3377
2 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1173225
1. TRUE ROUNDING
For sake of clarity on multiple lines (you can pack this into one equation).

Dummy = Dummy * 100 ;
Dummy = floor(Dummy + 0.5 ) ;
Dummy = Dummy / 100 ;

Do this before converting dummy to a string


or

2. ROUNDING FOR DISPLAY

change
cs.Format("Dummy = %f ",Dummy);
to
cs.Format("Dummy = %.2f ",Dummy);

0
 
LVL 2

Expert Comment

by:JYoungman
ID: 1173226
#include <math.h>
double round_two_places(double x)
{
    return ( floor(x*100.0 + 0.5) / 100.0 );
}
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Converting to C# also VS2015 5 125
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 428
c++ syntax question 9 48
Safe conversion? 4 67
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question