1
$\begingroup$

I am trying to run the following code using wolframscript on windows:

a = 123.4567891011213;
Print["a = ",a];
Print["a = ",AccountingForm[a,3]];

The output is:

a = 123.4567891011213
a = AccountingForm[123.4567891011213, 3]

Looks like none of the formatting commands work (e.g. I tried StringForm and it too remains unevaluated). I would just like to format the numbers to be a little shorter. Is it possible?

$\endgroup$
  • $\begingroup$ It works for me, output is a = 123.. What version are you using? $\endgroup$ – Rohit Namjoshi Oct 18 '19 at 1:56
  • $\begingroup$ 1.2.0 for Windows. $\endgroup$ – Mattia Landoni Oct 18 '19 at 2:05
  • $\begingroup$ 1.2.0? Did you mean 12.0? What does $Version evaluate to? $\endgroup$ – Rohit Namjoshi Oct 18 '19 at 2:10
  • $\begingroup$ My Mathematica version is 12.0.0 for Microsoft Windows (64-bit) (April 6, 2019). My Wolframscript version (typing wolframscript --version at the command line prompt) is WolframScript 1.2.0 for Windows. $\endgroup$ – Mattia Landoni Oct 18 '19 at 2:15
  • $\begingroup$ That is strange. I am on Mac OS, but that should not matter. I see Wolfram Language 12.0.0 Engine for Mac OS X x86 (64-bit) Copyright 1988-2019 Wolfram Research, Inc. In[1]:= a = 123.4567891011213; In[2]:= Print["a = ",a]; a = 123.457 In[3]:= Print["a = ",AccountingForm[a,3]]; a = 123. $\endgroup$ – Rohit Namjoshi Oct 18 '19 at 2:23
0
$\begingroup$

User Szabolcs's answer to this other question I asked yesterday also solves this problem.

The underlying cause is that default output format is ScriptForm and not OutputForm as it should be. To manually correct this behavior, it is enough to add SetOptions[$Output, FormatType -> OutputForm] at the beginning of the script.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Later on Wolfram got back to me. They said that upgrading Wolframscript to version 1.3.0 also solves the problem. (This is on Windows. As far as I can tell this was a Windows-only problem). $\endgroup$ – Mattia Landoni Oct 22 '19 at 5:01
  • $\begingroup$ It doesn't work in version 1.3.0. However changing the OutputForm seems to be great solution. $\endgroup$ – Sâu Oct 22 '19 at 8:18

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.