Rounding to arbitrary precision I am dealing with values that come from a measuring instrument. The instrument itself has a certain precision, i. e. it is limited in the resolution of values it can measure.
Let's assume the instrument is (physically) able to measure values with a precision of p = 0.003 mK (milli Kelvin).
When I get a value from the instrument, it is sent to me as a double, so no matter what the real value was, it is already "wrong" due to the floating point precision of a binary number.
Assume I get sent a value double t = 325.7269881 K.
Before I show the value to the user I must "round" it to the physical precision of p.
How to "round" correctly when an arbitrary precision (not 10^n) is given?
(Is this a "rounding" at all?)
All information on rounding I could find was rounding to a fixed count of digits or to some 10^n. But I think the problem I face is slightly different.
My first idea was to use something like this:
value = p * round(t / p)

where round rounds to the nearest integer.
For the example I would end up with v = 325.725.
For a precision of e. g. p_2 = 0.01 I would end up with "normal" rounding, i. e. v = 325.73
Is such an approach suitable for the problem? What would be alternatives?
 A: If the measuring instrument has a precision of 3 μK, then when you get the report of the temperature as 325726988.1 μK, that actually represents a temperature between 325726985.1 and 325726991.1 μK. You can write this this as 32572690 μK or as 32572.690 mK to indicate uncertainty in the last decimal place.  To round to the nearest 0.01 mK, use
round(t*100)/100

or simply report to the user
“*t*, plus or minus 0.003 mK”

The floating-point error in this case (assuming a 32-bit float) is on the order of 1e-07 μK, so you can forget about that; it will not affect your results, because the measuring device itself is a million times less precise.
A: The example seems flawed, since $325.727$ is not an integer multiple of $0.003$.
(The nearest integer multiple would be $325.728$ in this case, but I suppose
the "binary number" was supposed to be much closer to that value in the first place;
the double type in most computer languages is precise to more digits than shown here.)
But in general, the approach is correct.
For "rounding to a precision $p$" the most natural interpretation is
"rounding to the nearest integer multiple of $p$,"
whether or not $p$ happens to be a power of ten.
