Can you please neatly explain why the following two commands give different outputs?
N[1/3, 2]
0.33
N[1./3., 2]
0.333333
Thank you!
Can you please neatly explain why the following two commands give different outputs?
N[1/3, 2]
0.33
N[1./3., 2]
0.333333
Thank you!
N ref page 3rd example’s note:
With machine-precision input, the results are always machine precision
Workaround:
N[1/3. // Rationalize, 2]
(* 0.33 *)
I think the function you look for is Round, that does give the result you (I think) expect:
Round[1/3, 0.01]
Round[1./3., 0.01]
gives:
0.33
0.33
Also what Kuba says: the function N is designed to give a numerical value of an exact expression. So it does not make much sense to give something with finite precise to the function. You have Round for that purpose…
Or perhaps:
NumberForm[1./3., 2]
(* 0.33 *)
Kuba, Sander, Murray, thank you for your responses.
Please browse the attached file. I understand that using “Round” is the correct solution.
Best!