How to Round Numbers in Calculation

Thread Starter

Raschedian

Joined Mar 21, 2019
8
Hello everyone!

I am not very new to electronics but new here.

I have been doing electronics in the past but in a very practical way, not dealing with any kind of theory and calculation. Lately, I have been studying some mathematics, physics, and some theory of electronics and so I'm calculating some things.

I am familiar with how to round numbers off for example when you're solving a physics or chemistry problem, rounding numbers off, significant digits and the whole story but it seems to me that that method simply does not work too well in electronics. Most of the time, if you round your numbers off based on the number of significant digits, you'll get numbers that make no practical or logical sense. Although, reading some books and trying to solve the examples therein, it's hard to know how many significant digits to assume in the first place.

Now my question is, how does an electrical engineer or electronics engineer normally deal with his numbers? I have read on some website that engineering is an "art" and that you should deal with numbers based on the situation and that, you'll learn how to do it after you've gathered some experience and "intuition." I do not know how true that could be.

I really would not mind even very comprehensive answers here even if you happen to kindly provide me with a whole pdf book to go through.
Another way that would help me clear my doubts here is if you would solve a typical problem somewhat more complicated and calculation-involved than the Ohm's law and explain how you do it step by step and what you assume each step of the way while solving the problem. Your help would be greatly appreciated.

Thank you!
 

dl324

Joined Mar 30, 2015
16,922
Welcome to AAC!

We round numbers the same way a math major would do it. There's no reason to do it differently.

Do you have some examples in mind?
 

pmd34

Joined Feb 22, 2014
527
Hi Raschedian, I guess it depends a lot on the situation. For simple calculations in a microctontoller etc. you can simply chop off significant figures here and there, if they are not critical. In other applications, you may have to round figures off to the nearest decimal place for example for battery control applications you can be working to the nearest 10mV. so keeping all your numbers in mV and then rounding off when you have finally processed all your numbers is OK. There are some cases where you can get accumulative rounding errors that can do strange things to your results if you don't try to accommodate them.

So I guess its a case of... what are you trying to control? How accurately do you have to control it? - all calculations should be done to at least a couple more significant figures than this.
 

Thread Starter

Raschedian

Joined Mar 21, 2019
8
Hi pmd34,


You're absolutely right. Thank you very much for the reply and sharing your experience! Much appreciated!
 

WBahn

Joined Mar 31, 2012
30,062
As in any practical field, you need to consider the application and the level of accuracy and precision you require to successfully complete the task. If I'm building a fence in my back yard and round my measurements to the nearest meter, I will likely have lots of problems. Similarly, no one in their right mind would consider making measurements for that project to the nearest micron. If I round them to the nearest centimeter, I have a pretty fair shot at getting things to work, but some things will likely be marginal and I may have some difficulties. If I do all of my calculations and measurements to the nearest millimeter, I will almost certainly have no problems, but will likely be spending more time getting the measurements and doing the calculations than is warranted. So something in between is likely good enough.

The same with electronics. For many, many, many applications, getting an answer to within 1% is more then good enough -- even 10% is sufficient in many instances. The uncertainties in the various parameters that determine actual performance usually limit you to those levels. Because of this, a general rule of thumb is to report values with three sig figs and perform intermediate work with two more to minimize accumulated round-off errors. But this is just a rule of thumb and there are certainly other applications where you have to do much better. . If you are designing a 16-bit DAC, for instance, your nominal resolution is the next best thing to six sig figs, and so much of your work needs to be good to seven or more.
 

MrChips

Joined Oct 2, 2009
30,810
Hah! I misunderstood the question. I was fixated on rounding for the purpose of displaying values on some form of readout.

Now I see that perhaps the TS is referring to rounding in engineering values in general.
As @WBahn points out, it really depends on the application and the required accuracy.

In electronics, ±10% and ±20% is often good enough.

If my DMM displays my power supply voltage as 4.863V that could be interpreted as 4.9V which could be good enough in one application and not in another.

If by calculation the circuit calls for a resistor value of 4862Ω I would be able to assess if a 4700Ω 5% resistor will be ok or not in that application.
 

MrChips

Joined Oct 2, 2009
30,810
Here is a specific example.

I need to turn on a red 20mA LED using an NPN GP transistor.
What is the value of the series resistor R1?



I can calculate the value knowing the LED current, forward voltage, and transistor collector-emitter turn-on voltage.

I don't sweat it. I know that any value resistor from 100Ω to 1000Ω would produce acceptable results. I would simply breadboard the circuit and find the R1 resistor value that produces adequate brightness from the LED.
 

Thread Starter

Raschedian

Joined Mar 21, 2019
8
Rounding in a computer is the same as rounding in math.
Why do you want to do rounding?
Give us some examples.
Hi MrChips! Thank you for the reply. I've been reading a book and have had problems with numbers in the first chapter. I'll pick one or two typical examples so I can use your knowledge and experience. I'll post the questions tomorrow. Thank you very much!
 

Thread Starter

Raschedian

Joined Mar 21, 2019
8
As in any practical field, you need to consider the application and the level of accuracy and precision you require to successfully complete the task. If I'm building a fence in my back yard and round my measurements to the nearest meter, I will likely have lots of problems. Similarly, no one in their right mind would consider making measurements for that project to the nearest micron. If I round them to the nearest centimeter, I have a pretty fair shot at getting things to work, but some things will likely be marginal and I may have some difficulties. If I do all of my calculations and measurements to the nearest millimeter, I will almost certainly have no problems, but will likely be spending more time getting the measurements and doing the calculations than is warranted. So something in between is likely good enough.

The same with electronics. For many, many, many applications, getting an answer to within 1% is more then good enough -- even 10% is sufficient in many instances. The uncertainties in the various parameters that determine actual performance usually limit you to those levels. Because of this, a general rule of thumb is to report values with three sig figs and perform intermediate work with two more to minimize accumulated round-off errors. But this is just a rule of thumb and there are certainly other applications where you have to do much better. . If you are designing a 16-bit DAC, for instance, your nominal resolution is the next best thing to six sig figs, and so much of your work needs to be good to seven or more.
Hi WBahn!
Thank you for the detailed explanation! Much appreciated. I understand what you're saying and appreciate the answer. Thank you very much!
 

Thread Starter

Raschedian

Joined Mar 21, 2019
8
Here is a specific example.

I need to turn on a red 20mA LED using an NPN GP transistor.
What is the value of the series resistor R1?



I can calculate the value knowing the LED current, forward voltage, and transistor collector-emitter turn-on voltage.

I don't sweat it. I know that any value resistor from 100Ω to 1000Ω would produce acceptable results. I would simply breadboard the circuit and find the R1 resistor value that produces adequate brightness from the LED.
Thank you very much for the detailed explanation, MrChips! It makes perfect sense. So I think, I'll pick a few typical examples from the current book I'm reading, give it some thought and analyze it based on a few hypothetical situations and run my thoughts by you so I can make sure I have understood the concept well. Thank you very much for taking the time and explaining everything in detail. Much appreciated!
 

MrAl

Joined Jun 17, 2014
11,486
Hi,

When rounding a typical way to do it is to just add 0.5 to the number and then take floor(x).
For example:
2.412

add 0.5 to get:
2.912

then floor(2.912)=2

so 2 is the result.

But if we started with
2.512

then adding 0.5 gives us 3.012 and floor(3.012) gives us 3.

There we were doing basic rounding.

Next, we usually want to round to a certain number of digits not just to a whole number.
What we can do is multiply by a power of 10, add 0.5, take the floor(x), then divide by the same power of 10.
Example:
2.512 rounded to 3 significant digits or 2 decimals to the right.
First we multiply by 100 and get 251.2, then add 0.5, we get 251.7, then take the floor(251.7) then we get 251 then divide by 100 and
the final result is 2.51 and that is 3 sig digits or 2 decimals to the right.

You have to be a little careful with this method because you could overflow with large numbers, but generally in electronics it works ok.

Now since you did not say what you were rounding, maybe you are rounding floats to integers. In that case you add a magic number and it turns it into a whole number. You can look that magic number up. You can also use floor(x) as above if you like but it may be slower.

In binary however it is a little different. That is because we only have either a whole unit or 1/2 of a whole unit (or sub unit). This changes the rules completely because a number like 1111.1111 will round to 10000 and so will 1111.1000, and a statistical analysis has shown in the past that the error distribution is better if we choose that 0.1 (which is 0.5 decimal) randomly rather than systematically like we did far above.
So sometimes 1111.1 will round to 10000 and other times it will round to 1111. This is when the calculation is part of a large number of calculations. This could also work better with the 0.5 examples above too.

So you see it could be a little different depending on how you want to round.
You can also use log base 10 to determine what power of 10 to multiply and divide by.
 

Thread Starter

Raschedian

Joined Mar 21, 2019
8
Thank you MrAl for the invaluable information. Since you kindly took the time and typed all those words here, would you please be kind enough to give me some context as well? Probably applying some of the above in a simple typical circuit or if you prefer, I'll provide you with some example of my choice?
Moreover, functions like "floor" are usually available in some programming languages like C or C++. I've never seen that function in any scientific hand calculator. Do you do most of your calculation on a compiler or some PC based program that uses a C or C++ compiler?
 

WBahn

Joined Mar 31, 2012
30,062
Moreover, functions like "floor" are usually available in some programming languages like C or C++. I've never seen that function in any scientific hand calculator. Do you do most of your calculation on a compiler or some PC based program that uses a C or C++ compiler?
Many scientific calculators, though not all, support the floor function. Sometimes it is called the 'int' function (take the integer value of the operand). Most programmable scientific calculators support it. Since there are many more functions than most calculators have buttons, the less frequently used ones (at least in the eyes of the designers) are made available via menus. You generally need to scour the owner's manual or search the internet to find out how as it is often nonintuitive.
 
Last edited:

wayneh

Joined Sep 9, 2010
17,498
I am familiar with how to round numbers off for example when you're solving a physics or chemistry problem, rounding numbers off, significant digits and the whole story but it seems to me that that method simply does not work too well in electronics. Most of the time, if you round your numbers off based on the number of significant digits, you'll get numbers that make no practical or logical sense.
I have to challenge this premise. Can you cite an example where paying attention to significant figures leads to an illogical outcome? Electronics is not fundamentally different than other fields of science or engineering when it comes to the limitations of measurement precision.

My experience is not electronics, but chemical engineering. I've always had a preference for not rounding during calculations, and paying attention to significant figures at only the inputs and the outputs. The usual case is that you have inputs, perhaps data, stated with a certain precision and you need to convert that into some other form of information. During the calculation you might call on certain constants and conversion factors. If I needed pi or e or the number of liters per gallon, I always used as many digits in those as I could recall (3.141592654, 2.718281828, 3.78541). Why? I found it made it easier to follow and double check the calculations. For one thing, having all those digits in the notes was like a fingerprint for my own work. I never saw anyone else do this and so when I saw all the digits I knew it was likely my own work. It also eliminates the confusion that can come from rounding during a long series of calculations. Being "exact" gives you confidence that you're following along and getting exactly the same results. Using spreadsheets enables this habit.

I can't think of a calculation I ever made (in the engineering world) that wasn't in the range of two to four significant figures. If you have only one significant digit, calculations are not your problem - you lack data. It's a rare data set that gives you more than four significant figures. Of course there are examples, but they're the exceptions to the rule.

Within the range of two to four, it's not usually hard to choose the right number of digits with which to report your results. If you work in a field, you'll have an intuition for what is reasonable and what is not. I used to have a lab tech that reported pH values to the third decimal. The meter she was using was not capable of that precision, let alone the calibration procedures and temperature control that would be required. If I reported measuring my home mains voltage at 120.01VAC, everyone here would know that was silly because the mains voltage will vary over time and so reporting it to two decimals is excessive. Maybe that's not the best example but I think you get my drift.
 

MrChips

Joined Oct 2, 2009
30,810
TS has yet to clarify why he is interested in rounding.
Is it for arithmetic in programming or is it for engineering tolerance.
 

WBahn

Joined Mar 31, 2012
30,062
Thank you MrAl for the invaluable information. Since you kindly took the time and typed all those words here, would you please be kind enough to give me some context as well? Probably applying some of the above in a simple typical circuit or if you prefer, I'll provide you with some example of my choice?
In your first post you said that you were comfortable with the concepts of rounding and sig figs and such.

In that case, one thing you can always do is just do a propagation of errors analysis for determining how many sig figs your results are good to in your electronics-related calculations.

Here's a good example for you to sink your teeth into.

You have two logic systems that have to be interfaced and one works on 2.5 V TTL logic levels and the other at 3.3 V TTL logic levels. The devices conform to the JEDEC standards (see Figure 3 in the following document).

https://www.analog.com/media/en/training-seminars/tutorials/MT-098.pdf

In addition to the I/O from each device, you also have the common 'ground' shared by the devices as well as the 2.5 V supply and the 3.3 V supply.

You want to use a simple two-resistor circuit for each interface.

So design two circuits -- one to translate valid 3.3 V signals to valid 2.5 V input signals and another to translate valid 2.5 V output signals to valid 3.3 V input signals. Assume that no input should be exposed to a voltage level outside of that device's power supply range. Also, you may assume that we are not concerned about speed or power dissipation. Don't worry about the current limitations as we will assume that we can make the multiplier of the resistors large enough to not violate those while at the same time keeping them small enough so that they aren't too sensitive to noise.

Then come up with component values based on the assumption that all outputs either 0 V or the corresponding Vcc voltage.

Then see how this is affected by the allowed range of the actual output voltage values.

Then see how that is affected by the allowable range of the Vcc values. Assume the 2.5 V supply is between 2.3 V and 2.7 V and that the 3.3 V supply is between 3.0 V and 3.6 V.

Then see how that is affected by the tolerance of the resistors.

One thing to keep in mind is that tolerances in electronics are usually pretty hard cutoff values and not, for instance, the standard deviations of some normal distribution.
 

Thread Starter

Raschedian

Joined Mar 21, 2019
8
Many scientific calculators, though not all, support the floor function. Sometimes it is called the 'int' function (take the integer value of the operand). Most programmable scientific calculators support it. Since there are many more functions than most calculators have buttons, the less frequently used ones (at least in the eyes of the designers) are made available via menus. You generally need to scour the owner's manual or search the internet to find out how as it is often nonintuitive.
Thank you WBahn! I like the language you use. It's very "mathematicy"!
 
Top