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.

The best way I can come up with to say "show me this fraction as a decimal number to M places, don't use scientific notation" is:

NumberForm[N[1/998001,2994],ExponentFunction->(Null&)]

It seems like that's an awful lot of typing for a very simple request.

Is it possible say it more concisely?

share|improve this question
    
I think that is the canonical way, but that doesn't mean there isn't something more terse. –  Mr.Wizard Jan 26 '12 at 19:42
2  
I don't think you can avoid it altogether. But if you find yourself doing it a lot, you can always use SetOptions... –  Andrzej Kozlowski Jan 26 '12 at 19:53
    
I can't use any of these values to plot becasue their Head changes to NumberForm and graphs don't understand this form. I need to plot and have the tooltip show decimal form, any suggested alterations to the above to make it work? –  Lara Jordan Apr 10 '13 at 7:24
add comment

3 Answers 3

up vote 12 down vote accepted

You can express any fraction/number to arbitrary decimal places by using a backtick followed by number of digits required. For example:

In[1]:= 4/3`20
Out[1]= 1.3333333333333333333

This is the same as N[4/3, 20]. Now combine this with AccountingForm, which never uses scientific notation to get the output that you desire.

AccountingForm[1/998001`2994]
Out[2]//AccountingForm= 0.0000010020030040050060070080090100110120130140...

However, be aware that AccountingForm uses parentheses for negative numbers:

AccountingForm[-1/998001`2994]
Out[3]//AccountingForm= (0.00000100200300400500600700800901001101201301401501601....

Daniel Lichtblau has a good point that although using `instead of N might be shorter in this case, in general, it might not give the same result — for example, compare the digits of Log[2`50] and N[Log[2],50]. You'll see that they differ in the last couple of digits. However, for small use cases, the difference might be insignificant.

share|improve this answer
    
I also thought of AccountingForm (and RealDigits), but I think the negative numbers are an issue. –  Mr.Wizard Jan 26 '12 at 19:59
    
@Mr.Wizard Yes, but I also noticed that it uses () for negative numbers, which could be used to distinguish if one were to use this only for quick visual checking –  rm -rf Jan 26 '12 at 20:01
    
I am voting for this since I think AccountingForm comes closest. –  Mr.Wizard Jan 26 '12 at 21:16
2  
Might just use N[...,m]. Check difference between Log[2`20] and N[Log[2],20]. The former will lose a digit. (Might not be important for the purposes at hand, though.) –  Daniel Lichtblau Jan 27 '12 at 0:09
add comment

You could always set $Post to have this happen automatically.

format[x_Real] := NumberForm[x, ExponentFunction -> (Null &)];
format[x_] := x;
$Post = format;

Now,

N[1/998001, 50]

returns

0.0000010020030040050060070080090100110120130140150160170

Even better, $Post is applied at display time, thus

Head[%]

returns Real.

share|improve this answer
add comment

As long as your numbers are positive you could use AccountingForm.

In[12]:= AccountingForm[N[1/998001,50]]

Out[12]//AccountingForm= 0.0000010020030040050060070080090100110120130140150160170
share|improve this answer
add comment

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.