Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*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 1995

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

Search the Archive

Short form for FortranForm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2863] Short form for FortranForm
  • From: "hedonley at grove.iup.edu"@grove.iup.edu
  • Date: Sat, 30 Dec 1995 01:01:44 -0500
  • Organization: Indiana University of Pennsylvania

>Subject: Short form for FortranForm
>From: hedonley at grove.iup.edu (H. Edward Donley)
>To: mathgroup at smc.vnet.net
>Organization: Indiana University of PA

Does anyone know how to create FortranForm numbers with just a few digits
of precision, something analogous to the second argument of N[number,
precision]?  My attempt, below, worked for the first example but not for
the second.  And I have a suspicion that there is a much simpler solution.

  In[1]:=
    CompactForm[a_Real, precisiongoal_Integer] :=
      Module[{digits,scalefactor},
        digits = Log[10, Abs[a]];
        scalefactor =
          10^(Sign[digits] Floor[Abs[digits]] - precisiongoal);
        FortranForm[N[ Round[a/scalefactor] scalefactor ]]
      ];
    CompactForm[.0000000005325436656768678,3]
    CompactForm[53254366567686.78,3]

  Out[2]//FortranForm=
    5.33e-10
  Out[3]//FortranForm=
    5.325000000000001e13

Thanks for any help you can give to me.

Ed Donley

-- 
H. Edward Donley
Mathematics Department
Indiana University of Pennsylvania
Indiana, PA  15705
U.S.A.

hedonley at grove.iup.edu
http://www.ma.iup.edu/MathDept/Professors/HDonley.html


  • Prev by Date: Re: Re: FindMinimum and NIntegrate
  • Next by Date: Should I get Matlab or Mathematica or ?
  • Previous by thread: Mathematica vs ?
  • Next by thread: Short form for FortranForm