I have data from a Multimeter that has a precision of 0.6%rdg+4dgt. So i want to take the last digit of, say, 12.007
and add 4 to the last digit like 12.011
.
I'm doing RealDigits[12.007,10,5][[1,-1]]
add 4 and then somehow withFromDigits
get the result...it seems trivial but i don't see how.
$\begingroup$
$\endgroup$
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
3
Perhaps something like:
ClearAll[func];
func[add_, pos_: (-1)] := N@FromDigits@MapAt[# + add &, RealDigits[##], {{1, pos}}] &
func[4, -1][12.007, 10, 5]
(* 12.011` *)
func[4, -3][12.707, 10, 5]
(* 13.107` *)
-
$\begingroup$ it works fine but i want to use it in a rule like
{a_,b_}->{a,fun[4,-1]@b}
but it seems that first apply the function to a and then the substitution rule. $\endgroup$ Commented Sep 1, 2014 at 14:11 -
1$\begingroup$ @Kafkarudo, can you give an example for the list you are trying to transform? Btw, perhaps you need
:>
instead of->
? $\endgroup$– kglrCommented Sep 1, 2014 at 14:23 -
$\begingroup$ yep, the :> did it! thank a lot. $\endgroup$ Commented Sep 1, 2014 at 14:28