0
|
3818 Views
|
5 Replies
|
6 Total Likes
View groups...
Share
GROUPS:

# Expressing numbers in fortran form

Posted 12 years ago
 I want to use FortranForm to make 0.0000776146 turn into 7.8e-5   i.e. I want to do the following:FortranForm[0.0000776146]output: 7.8e-5But 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.
5 Replies
Sort By:
Posted 11 years ago
 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 12 years ago
 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 12 years ago
 It looks like the LaTeX conversion is having some difficulty with the Row[] construct, e.g. this does not workTeXForm[Row[{"test"}]]As a workaround, I'd try the followingNumberForm[0.00007761457094412894, 2, ExponentFunction -> (# &), NumberFormat -> (#1 ~~ "e" ~~ #3 &)]
Posted 12 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 12 years ago
 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 *)