2
$\begingroup$

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

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` *)
$\endgroup$
3
  • $\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$
    – Kafkarudo
    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$
    – kglr
    Sep 1, 2014 at 14:23
  • $\begingroup$ yep, the :> did it! thank a lot. $\endgroup$
    – Kafkarudo
    Sep 1, 2014 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.