Message Boards Message Boards

5 Replies
6 Total Likes
View groups...
Share this post:

Expressing numbers in fortran form

Posted 11 years ago
I want to use FortranForm to make 0.0000776146 turn into 7.8e-5   i.e. I want to do the following:
output: 7.8e-5

But all i get is:
output: 0.00007761457094412894 (this is the actual numebr, the frst is rounded).

I tried palying around with using both FortranForm and NumberForm but It seems I can't use both without running into problems. 

Any help is appreciated. Thank you.
POSTED BY: Jesse Kanter
5 Replies
An approach using constructs like NumberForm is certainly a good way to go.  In this context it is worth noting that FortranForm is a funciton that was introduced in Version 1 of Mathematica and has not been updated since.  So, though it is useful in some contexts, to be more "modern" one has to often write custom code for things like this using the much more versatile functions such as NumberForm and so on. 
POSTED BY: David Reiss
Jesse Kanter, welcome to Wolfram Community! If you find answers useful please give them a vote-up. Also, please note how your post was formatted to place code in designated code blocks. This is done for easy copy-paste code operations between posts and Mathematica notebook. Take a look at other posts to see the standards of formatting. Please follow this format in the future using editor buttons as shown below:
POSTED BY: Moderation Team
It looks like the LaTeX conversion is having some difficulty with the Row[] construct, e.g. this does not work
As a workaround, I'd try the following
NumberForm[0.00007761457094412894, 2, ExponentFunction -> (# &), NumberFormat -> (#1 ~~ "e" ~~ #3 &)]
POSTED BY: Ilian Gachevski
Posted 11 years ago
Thanks Llian! that worked great. Follow up question, Is there any reason why after using the code: 
NumberForm[0.00007761457094412894, 2, ExponentFunction -> (# &), NumberFormat -> (Row[{#1, "e", #3}] &)]
That I wouldn't be able to save the mathematica  notebook this is used in as a LaTex file?
POSTED BY: Jesse Kanter
I believe FortranForm will only use 'e' for exponents outside the range from -5 to 5, however NumberForm is very customizable and could be used instead, for example:

NumberForm[0.00007761457094412894, 2, ExponentFunction -> (# &), NumberFormat -> (Row[{#1, "e", #3}] &)]

(* Out[5]= 7.8e-5 *)
POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract