Jun-08-2021, 02:10 PM
Hello everyone,
I'm familiar with the rounding function in python but at work I encountered a new situation.
Say you have a measurement result like so: (3.406 ± 0,052) mg/L.
There is a norm (DIN 1333) we use which states, that the result 3.406 mg/L has to be rounded to 3.41 mg/L according to its' uncertainty of 0.052 mg/L because the first digit behind the comma which differs from zero (in this case 5) occurs at the second decimal place.
To make matters more complicated a result like (9.4053 ± 0,021) mg/L has to be rounded to 9.405 mg/L because even though the uncertainty also "starts" at the second digit after the comma, the digit there is <3 and therefore the rounding place moves "one to the right".
Accordingly (1,024.45 ± 10.5 ) mg/L should be rounded to 1024 mg/L
and (1,024.45 ± 30.4 ) mg/L should be rounded to 1020 mg/L.
The latter (numbers bigger than zero) can be understood if you just write the values in exponential form like 10.2445 * 10^-2 and 0.105 * 10^-2.
How can I implement this in python without creating a barrage of if statements? In short: is there a simple rounding function which takes uncertainty into account?
Thanks in advance
Markus
In short
I'm familiar with the rounding function in python but at work I encountered a new situation.
Say you have a measurement result like so: (3.406 ± 0,052) mg/L.
There is a norm (DIN 1333) we use which states, that the result 3.406 mg/L has to be rounded to 3.41 mg/L according to its' uncertainty of 0.052 mg/L because the first digit behind the comma which differs from zero (in this case 5) occurs at the second decimal place.
To make matters more complicated a result like (9.4053 ± 0,021) mg/L has to be rounded to 9.405 mg/L because even though the uncertainty also "starts" at the second digit after the comma, the digit there is <3 and therefore the rounding place moves "one to the right".
Accordingly (1,024.45 ± 10.5 ) mg/L should be rounded to 1024 mg/L
and (1,024.45 ± 30.4 ) mg/L should be rounded to 1020 mg/L.
The latter (numbers bigger than zero) can be understood if you just write the values in exponential form like 10.2445 * 10^-2 and 0.105 * 10^-2.
How can I implement this in python without creating a barrage of if statements? In short: is there a simple rounding function which takes uncertainty into account?
Thanks in advance
Markus
In short