Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a lot of data to inspect. An example of a number in my program is

123.189094

This gets displayed as

123.189

Unfortunately, most of my information is in the small digits, so, when visually inspecting this data, 123.189094 and 123.189263 are not distinguishable, in other words, a list like

{123.189094, 123.189263}

is displayed like

{123.189, 123.189}

and it looks like I have equal data when I don't. The only fix I have found for this is FullForm, but that explodes out all the structure (lists, rules, etc.) and makes the display very annoying. Imagine that my data were actually buried deep in some nested structure of lists and rules (and it is).

{123.189094, 123.189263}//FullForm
(* List[123.189094`,123.189263`] *)

is not what I want. I would have thought N[#,10]& or somesuch would work, but it doesn't

{123.189094, 123.189263} // N[#, 10] &
(* {123.189,123.189} AAACH! *)

StandardForm doesn't do it, TraditionalForm doesn't do it.

I'm stuck. As usual, will be grateful for any advice or ideas.

share|improve this question
1  
Related: Mathematica Precision –  Brett Champion Mar 30 '12 at 23:16
5  
It is possible to set the number of digits in Preferences->Appearance->Numbers->Formatting –  Andrew Mar 31 '12 at 7:34

6 Answers 6

up vote 14 down vote accepted

Maybe this :

NumberForm[#, 10] &@ {123.189094`, 123.189263`}
{123.189094, 123.189263 }

?

Edit

Consider also this utility of NumberForm[ x, {m, k}] giving m real digits of x with k digits to the right of the decimal point, e.g.

NumberForm[#, {10, 7}] &@ { 197.9898987322333, 201.73205080756887 }
{ 197.9898987, 201.7320508 }
share|improve this answer
    
But if I have a list of numbers, after applying NumberForm, I can't access the list elements as usual, but with an extra index, for example what was before mylist[[1]] is now mylist[[1]][[1]]. How can avoid this? I need to pass this list to a function. –  Santi Apr 24 at 10:09
    
I would make it like this f[ NumberForm[#, {10, 7}]& @ list]. –  Artes Apr 24 at 10:55
    
Sorry @Artes, but that still doesn't work. NumberForm returns something that has not the same structure as my original list. Using First[NumberForm[#, {10, 7}]& @ list] returns something that still has other structure, with a list . And then if I do First[First[NumberForm[#, {10, 7}]& @ list]] it returns only a list with the original "old" precision digits. –  Santi Apr 29 at 16:18
    
@Santi If you have some problems you should ask another question checking if there is no one similar. Here I solved the OP problem. Why should I bother some unclear questions? I believe you would rather use something different but there is no precise information. Perhaps you should check RootApproximant or with the second argument Rationalize or Chop or Round or ... –  Artes Apr 29 at 17:10

If this is something you want in general, try:

SetOptions[$FrontEnd, PrintPrecision-> 10]

and if you just want it for a specific notebook, then do:

SetOptions[InputNotebook[], PrintPrecision-> 10]
share|improve this answer

PrintPrecision

You can control the number of digits displayed using the PrintPrecision option.

You have a number of options for its use. You can set it Globally or for the specific Notebook using the Options Inspector. You can also use it directly with Style:

Style[123.189094, PrintPrecision -> 10]
123.189094

You can set it temporarily for one session like this:

SetOptions[$FrontEndSession, PrintPrecision -> 10]

Finally you can set it using Style Sheets (select cell type Output).


Arbitrary precision arithmetic

If you use arbitrary precision arithmetic Mathematica automatically displays all digits. If you are concerned with the small end of numbers you should probably be using arbitrary precision anyway. Please see the second half of this answer for more.

123.189094`9
123.189094
share|improve this answer
    
No upvotes? I'll help you play ketchup. You and @RolfMertig. These are the answers, the other's are (some good) workarounds. It's not a question about precision and there's no need to wrap the result in some inert structure only for the FE to hide less of what it already received from the kernel –  Rojo Mar 31 '12 at 6:22
    
@Rojo thanks. By the way, please see my updated "Splitting" answer (the first one). I'm still chasing the perfection of doing it with a single pattern, but Mathematica is not yielding easily. –  Mr.Wizard Mar 31 '12 at 6:59

InputForm gives

  {123.189094, 123.189263} // InputForm
  (*==> {123.189094, 123.189263}  *)
share|improve this answer

The other answers are fine, but if all the interest is in the small-end digits, consider something like:

((RealDigits /@ {123.189094`, 123.189263`}) /. 
  {a__, 0..} -> {a})[[All, 1, -4 ;; -1]]
{{9, 0, 9, 4}, {9, 2, 6, 3}}

This picks up the smallest-end non-zero digits so you can focus on them. This won't work if your numbers have a different number of digits. If that's the case, you will have to allow for this by instead dropping the first few digits from the RealDigits results and then removing the trailing zeros.

(RealDigits /@ {123.189094`, 123.189263`})[[All, 1, 5 ;; -1]] /. 
  {a__, 0 ..} -> {a}// TableForm
 8  9   0   9   4
 8  9   2   6   3
share|improve this answer

Use NumberForm:

NumberForm[{123.189094, 123.189263}, 9]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.