# Format data consistently with Around

I don't like that Around uses two different styles to display data. Depending on the magnitude it seems to either use 0.123456(78) or it uses 0.12345 $$\pm$$ 0.00067. See for example the output of:

SeedRandom[1234];
Around[RandomReal[], 10.^-RandomReal[{1, 8}] RandomReal[]] & /@
Range[10]


Is there a way to always display the error in the 0.123456(78) style which I prefer?

• you should accept jose's answer, it solved the issue for me!
– Q.P.
Dec 1, 2021 at 20:32

## 2 Answers

The different typesetting forms of Around are controlled via internal thresholds.

The 0.123456(78) notation is only appropriate for cases in which the uncertainty is smaller than the (absolute value of the) center value, so we can set this:

LanguageUncertaintyDump$redThreshold = 1  to make all such cases typeset with your preferred notation. If you always want to get the standard plus-minus notation then set that threshold to 0 . Okay so first: ## THIS IS A HORRIBLE HACK AND ONLY USABLE FOR DISPLAY PURPOSES I crawled a bit the code of Around with GeneralUtilitiesPrintDefinitions@Around  The function which does emit the right display box is called redpmStructure I extracted the necessary code for it to work: accuracyFromUDT[sigma_]:= Max[0,Accuracy[SetPrecision[sigma, Max[Log10[N[35.5]] - 1,$MinPrecision]]]];

daBox[x_,DirectedInfinity[1]]:= ToBoxes @ DecimalForm @ x;
daBox[x_,acc_]:= If[TrueQ[Less[Abs @ x, 10 ^ (-acc)]],
ToBoxes @ DecimalForm[0., {Infinity, Max[0, acc]}],
If[Less[Precision @ x, MachinePrecision],
ToBoxes @ DecimalForm[N @ x, {Infinity, Max[0, acc]}],
ToBoxes @ DecimalForm[x, {Infinity, Max[0, acc]}]
]
];
stringofbox[TagBox[box_, __]] := stringofbox@ box;
stringofbox[InterpretationBox[box_,__]] :=stringofbox @ box;
stringofbox[string_String]:= StringDrop[StringDrop[string, 1], -1];
stringofbox[box_]:= box;

daString[x_,acc_]:=stringofbox @ daBox[x, acc];

redpmStructure[x_,sigma_]:=Module[{acc,sigmam, sigmae, sigmastring, xstring, n},
{sigmam,sigmae}=MantissaExponent[sigma];
If[ExactNumberQ[sigmam], sigmam = N @ sigmam];
acc = Ceiling @ accuracyFromUDT@ sigmam;
sigmastring =daString[sigmam, acc];
If[SameQ[StringTake[sigmastring, 1], "1"],
sigmastring = StringJoin["1", ConstantArray["0", acc]],
sigmastring = StringDrop[sigmastring, 2];
];
xstring =daString[x, acc + -sigmae];
n = StringLength @ sigmastring;
{StringDrop[xstring, -n], StringTake[xstring, -n], sigmastring, 0}
];

makeAroundTemplateBox[{xbox_,rbox_,sigmabox_, 0}] := TemplateBox[{xbox, rbox, sigmabox}, "AroundSeq"];

MakeBoxes[DisplayAround[x_,sigma_],fmt_]:= With[{box=makeAroundTemplateBox@redpmStructure[x,sigma]},InterpretationBox[box,Around[x,sigma]]]
DisplayAround[Around[x_,sigma_]]:=DisplayAround[x,sigma]


If you evaluate the code above, you can simply write:

DisplayAround[0.1561085196,0.00187]


0.15(61±19)

Or more convenient for you:

val=Around[0.1561085196,0.00187];
DisplayAround[val]
`

I feel dirty but it seems to work.

I want to stress here again: do not do anything else with that except display a number!!

Edit: There seem to be cases, when the estimator and error are above 1 where the estimator is truncated too strongly. So it's not even bug free. If I were you, I'd probably jsut write DisplayAround from the ground up. Should be easier than finding this bug in there.