Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: InputForm Query

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19751] Re: InputForm Query
  • From: "David Bailey" <db at salford-software.com>
  • Date: Wed, 15 Sep 1999 03:53:03 -0400
  • Organization: University of Salford, Salford, Manchester, UK
  • References: <7redv6$487@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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