473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

RoundTo

Hello
What am i supposed to do to be able to use RoundTo function?

Thanx
Jul 22 '05 #1
3 5306
Wojtek wrote:
Hello
What am i supposed to do to be able to use RoundTo function?


There is no such thing as a function "RoundTo" in standard C++. You
should ask in a newsgroup about your compiler.

Jul 22 '05 #2
Wojtek wrote:
Hello
What am i supposed to do to be able to use RoundTo function?

Thanx


Maybe there is a more efficient method, but here is the code i use:
#include<iostream>
#include <cmath>

using std::cout;
using std::endl;
using std::pow;
double round(double number, int digits){
int mul = (int)pow((double)10,(double)digits);
number*=mul;
if(number>0)
number+=0.5;
else
number-=0.5;
number=static_cast<int>(number);
number/=mul;
return number;
}

main () {
double a=4.34678,b;
b=round(a,3);
cout << a << ";"<<b<< endl;
a=-542.6715;
b=round(a,3);
cout << a << ";"<<b<< endl;
}

regards marbac
Jul 22 '05 #3
Wojtek wrote:
Hello
What am i supposed to do to be able to use RoundTo function?

Thanx


Maybe there is a more efficient method, but here is the code i use:

#include<iostream>
#include <cmath>
using std::cout;
using std::endl;
using std::pow;
double round(double number, int digits){
int mul = (int)pow((double)10,(double)digits);
number*=mul;
if(number>0)
number+=0.5;
else
number-=0.5;
number=(int)number;
number/=mul;
return number;
}

main () {
double a=4.34678,b;
b=round(a,3);
cout << a << ";"<<b<< endl;
a=-542.6715;
b=round(a,3);
cout << a << ";"<<b<< endl;
}

regards marbac
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: stevek | last post by:
How do I format an integer. Add commas. 1234565 1,234,565 TIA
5
by: ibiza | last post by:
Hi all, I'd need a function that would rounds values like : d = roundTo(64.2, 0.25) ' returns 64.25 d = roundTo(64.2, 10) ' returns 64 d = roundTo(64.2, 100) ' returns 100 well, that rounds...
4
by: scott | last post by:
Hi! I have a table with a StartTime and EndTime and want to calculate number of hours worked. Is it possible to get a "Number" answer? E.g. 9:00am (StartTime) worked to 4:00pm (EndTime) = 7...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.