Message Boards Message Boards

0
|
4402 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Difference between N[1/3, 2] -vs- N[1./3., 2]?

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!

4 Replies

Kuba, Sander, Murray, thank you for your responses. Please browse the attached file. I understand that using "Round" is the correct solution. Best!

Attachments:

Or perhaps:

     NumberForm[1./3., 2]
(*  0.33  *)
POSTED BY: Murray Eisenberg

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...

POSTED BY: Sander Huisman

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 *)
POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract