I have the following set of equations:

xs = 9295050963679385441209;
ys = 10721945986215692199666;
x = xs - 10000;
exponent = 0.666451549104308964``18;
xs1gt = Power[xs,exponent];

Which should produce ~437295921404696.997750975489799605.

If I naively print xs1gt, I get this:


I looked for solutions on StackExchange, and I found the How to avoid the scientific notation in output? thread. Unfortunately, none of the solutions proposed there worked:

AccountingForm[xs1gt, 33]
DecimalForm[xs1gt, {15, 18}]
N[xs1gt, 33]
NumberForm[xs1gt, 33]
NumberForm[xs1gt, 33, ExponentFunction->(Null&)]
NumberForm[xs1gt, 33, ScientificNotationThreshold->{-Infinity, Infinity}]



I searched high and low for alternatives, and I stumbled upon InputForm and SetPrecision, which finally gave me satisfactory results:

SetPrecision[xs1gt, 33]



Now my question is why didn't the other approaches, i.e. AccountingForm, DecimalForm and NumberForm, produce a similar result with 33 significant figures of precision (15 digits and 18 decimals)? I am especially confused by DecimalForm not having worked the way I expected.

  • 1
    $\begingroup$ The requested precision in the *Form wrapper seems not override the precision of the number and uses the precision as a limit on the number of sig figs, with excess digits being padded with zero if necessary. It is similar to the behavior of RealDigits and fits with the Mathematica notion of Precision. Is DecimalForm[SetPrecision[xs1gt, 33], {33, 18}] a good enough workaround? $\endgroup$
    – Michael E2
    Commented May 11, 2021 at 13:50
  • $\begingroup$ Yes, using "DecimalForm" together with "SetPrecision" is a good solution for me. I wanted to understand why the other solutions didn't work though, an issue which is addressed by the first part of your comment. $\endgroup$ Commented May 11, 2021 at 13:52
  • 1
    $\begingroup$ A simplistic explanation is that 18 is not enough accuracy for exponent. Try these two modifications: exponent = SetAccuracy[0.666451549104308964, 50] (or use the double backtick form) and DecimalForm[xs1gt, {33, 18}]. Does this give the desired result? $\endgroup$
    – LouisB
    Commented May 11, 2021 at 20:50
  • $\begingroup$ Wow, that worked. Thanks @LouisB!! $\endgroup$ Commented May 12, 2021 at 7:04


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.