MathGroup Archive 1994

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

Search the Archive

real number -> scientific C like string

Dear Mathgroupers,

I need a conversion of a real number to a string containing that number
in scientific and C-like format:


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]
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->(#&)]
Out[6]//NumberForm= {2.345 10  }
In[7]:= CForm[NumberForm[{a}, ExponentFunction->(#&)]]
Out[7]//CForm= NumberForm(List(0.002345),

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

  • Prev by Date: Mathematica Programming
  • Next by Date: Re: Math on Sun..Help!
  • Previous by thread: Mathematica Programming
  • Next by thread: Re: real number -> scientific C like string