0
$\begingroup$

I am using wolframscript.exe to learn mathematica and I would expect the following code to return 0.7071:

Print[N[Sin[Pi/4],5]];

But instead, when ran using:

wolframscript.exe -file "myfile.wl"

I get the following output instead:

0.7071067811865474617`5.

Am I misunderstanding how N works?

$\endgroup$
4
  • $\begingroup$ N[Sin[Pi/4], 5] indicates that you want the precision tracked and controlled to provide a result with a precision of 5 digits. It does not control the display of the number. The `5 in the result indicates that the result achieved a precision of 5 digits; the rest of the digits are what is stored. $\endgroup$
    – Bob Hanlon
    Commented Nov 6, 2021 at 19:52
  • $\begingroup$ Ok I see, so how do I control the display so that it's no more than 5 digits? $\endgroup$
    – mbl
    Commented Nov 6, 2021 at 19:55
  • $\begingroup$ I don't use wolframscript but have you tried NumberForm $\endgroup$
    – Bob Hanlon
    Commented Nov 6, 2021 at 19:59
  • $\begingroup$ @bbgodfrey Yep that answers it! Syed already posted this. Thank you both. $\endgroup$
    – mbl
    Commented Nov 7, 2021 at 0:48

0