real number -> scientific C like string
- To: mathgroup at christensen.cybernetics.net
- Subject: real number -> scientific C like string
- From: schnoerr at ipesgi.e-technik.uni-stuttgart.de (Claudius Schnoerr)
- Date: Fri, 21 Oct 1994 10:06:11 +0200 (MDT)
Dear Mathgroupers,
I need a conversion of a real number to a string containing that number
in scientific and C-like format:
Example:
In[1]:= CForm[2345.67 10^7]
Out[1]//CForm= 2.34567e10
In[2]:= ToString[CForm[2345.67 10^7]] // FullForm
Out[1]//FullForm= "2.34567e10"
This is the desired result, but this will not work with smaller exponents:
In[3]:= a = 0.002345
Out[3]= 0.002345
In[4]:= ToString[CForm[a]]
Out[4]= 0.002345
This is not in scientific notation. Another try:
In[4]:= ScientificForm[a]
-3
Out[4]//ScientificForm= 2.345 10
In[5]:= CForm[ScientificForm[a]]
Out[5]//CForm= ScientificForm(0.002345)
Yet another try:
In[6]:= NumberForm[{a}, ExponentFunction->(#&)]
-3
Out[6]//NumberForm= {2.345 10 }
In[7]:= CForm[NumberForm[{a}, ExponentFunction->(#&)]]
Out[7]//CForm= NumberForm(List(0.002345),
Rule(ExponentFunction,Function(Slot(1))))
Has anybody an idea ? Please e-mail to me.
--
---------------------------------------------------------------------
Claudius Schn"orr Institut f"ur Physikalische Elektronik
Universit"at Stuttgart
Pfaffenwaldring 47
Tel: ++49-711-685-7168 70569 Stuttgart
FAX: -7143
e-mail:schnoerr at ipesgi.e-technik.uni-stuttgart.de
---------------------------------------------------------------------