MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: InputForm Query


Brian Higgins <bghiggins at ucdavis.edu> wrote in message
news:7redv6$487 at smc.vnet.net...
> I am using MathScript to post expression evaluated by the kernel into
> web pages. When the expressions are algebraically complex, I wrap the
> output from the kernel with InputForm. For example(a simple case),
>
> In[1]:=InputForm[1 + 7/13.*x^2]
>
> Out[1]//InputForm=
> 1 + 0.5384615384615385*x^2
>
> The question for the Mathgroup is whether there is a simple way to
> automatically truncate the numeric number(s) in the expression so that
> all numerical quantities are displayed with a specified number of
> digits. When the output from the kernel is purely numerical, then it is
> a simple matter to use NumberForm.
> Thanks much,

NumberForm will work on expressions, but it only acts as a wrapper - so you
do not see the effect in InputForm (which you need to flatten out your
exponents). One answer is to apply NumberForm to the expression and convert
to a string. Then if you convert this back you will have truncated the
number: For example:

In[58]:=
NumberForm[1 + 7/13.*x^2, 4] // ToString // ToExpression // InputForm

Out[58]//InputForm=
1 + 0.5385*x

Maybe there is a neater way?

David Bailey

Salford Software




  • Prev by Date: Re: Mathematica can't win against Tiger Woods
  • Next by Date: Subject: Re: RE: Finding a relative prime
  • Previous by thread: InputForm Query
  • Next by thread: Mathreader on a CD