473,378 Members | 1,417 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,378 software developers and data experts.

How to round off a number to certain significant figures using C++?

Could anyone tell me how to round off a number to certain significant
figures using C++?

For example, how to round off a number 12567 to 13000 (2 significant
figures)?
Jul 22 '05 #1
2 9458
"Andy" <an*****@gmail.com> wrote...
Could anyone tell me how to round off a number to certain significant
figures using C++?

For example, how to round off a number 12567 to 13000 (2 significant
figures)?


Look on http://groups.google.com for "implement rounding c++". You will
find plenty of solutions.

V
Jul 22 '05 #2
an*****@gmail.com (Andy) wrote in message news:<ad*************************@posting.google.c om>...
Could anyone tell me how to round off a number to certain significant
figures using C++?

For example, how to round off a number 12567 to 13000 (2 significant
figures)?


How would you do in on paper? Let me guess, you take the 3rd digit
(3, since you want to keep only 2 digits). If this third digit is
[0..4], set it and the digits following to 0. If the digit is
[5..9], increase the second digit (which may overflow, it it's 9)
and set the 3rd and following digits to 0.

Now, splitting a number into decimal digits is a bit tricky. You
need to know that the modulo operator in C++ is called '%', e.g.
25 modulo 10 is written (25%10)==5

HTH,
Michiel Salters
Jul 22 '05 #3

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

Similar topics

11
by: Russell E. Owen | last post by:
I realize this probably a stupid question, but...is it safe to round to the nearest integer by using int(round(val))? I suspect it is fine, but wanted to be sure that weird floating point...
79
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current...
8
by: David Corby | last post by:
Hi everybody, I've got a problem. I'm trying to round a double to a particular number of significant digits, in this case 5, but I can't figure out a way around getting _exactly_ what I want...
9
by: kdlittle88 | last post by:
Does anyone have any sample code on how to round off a float to x digits? say for example rounding 3.1415 to 3.1? Any help would be appreciated. I am learning C++ and have not found this info...
3
by: mg | last post by:
Hi everybody... We try to white scripts with Pyrhon 2.4 for an acoustic simulation and we wrote these follow lines : <begin script> c = 340 i =j=k= 1 sum_ = 23 table =
40
by: RadiationX | last post by:
I have a problem that I really don't understand at all. In my previous post I could get started on my projects I just had a few problems with syntax errors. This problem is something that I don't...
4
by: Chris Davoli | last post by:
The folllowing will round to 526, but it should round to 527. It works correctly for all other numbers, except for this one. Does anybody know of a bug in Math.Round? Dim ldecWater As Decimal =...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
7
by: ma740988 | last post by:
Consider the equation (flight dynamics stuff): Yaw (Degrees) = Azimuth Angle(Radians) * 180 (Degrees) / 3.1415926535897932384626433832795 (Radians) There's a valid reason to use single...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.