Solved

Rounding off values

Posted on 1998-09-21
2
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 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