Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have some very small values such as 2.601519253*10^-8. I'd like to output these values to CSV for another program to work with. I've tried N[value, 50], but Mathematica still insists on producing scientific notation (which my program can't read).

How can I force Mathematica to output values in decimal form?

EDIT:

AccountingForm seems to be the answer to my question. AccountingForm[2.601519253458693*10^-8, 30] gives a nice decimal format I can use. –

share|improve this question

marked as duplicate by Ajasja, Artes, Sjoerd C. de Vries, Yves Klett, Silvia Apr 28 '13 at 21:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
Maybe NumberForm is what you're looking for. –  Silvia Dec 12 '12 at 6:08
    
NumberForm[2.601519253458693*10^8, 30] Still results in scientific notation. Annoyingly. AccountingForm seems to be the answer to my question. AccountingForm[2.601519253458693*10^-8, 30] gives a nice decimal format I can use. –  Steven Dec 12 '12 at 6:15
    
What about Export? –  Sjoerd C. de Vries Dec 12 '12 at 6:31
2  
Duplicate of: mathematica.stackexchange.com/q/771/5 –  rm -rf Dec 12 '12 at 22:53
add comment

2 Answers 2

up vote 7 down vote accepted

How to format

Using AccountingForm :

I show first the output of one function for your number

n = 2.60152*10^-8  (*your number *)
padIt[n, {15, 14}]

(*  +0.00000002601519  *)

the first parameter is the number to format, then there is a list of 2 numbers. The first is the total number of digits you want in the field. The second number is how many digits to the right of the decimal point. This function adds zeros to the left of the decimal point if there are no other digits to fill in. This is I need to make sure the field width is always the same for each number. You can change these options as you need. Here is the function

padIt[v_?(Element[#, Reals] &), f_List] :=  AccountingForm[Chop[v] , f, 
                 NumberSigns -> {"-", "+"}, 
                 NumberPadding -> {"0", "0"}, 
                 SignPadding -> True];

You can change the above options shown to customize it as needed. (remove the +,- sign, change padding, etc..)

update

How to export

SjoerdC.deVries asked a good question in the comment above on how to export these numbers to a text file. This below shows one way to do it

Clear["Global`*"]
SetDirectory[NotebookDirectory[]];
padIt[v_?(Element[#, Reals] &), f_List] := 
  AccountingForm[Chop[v] , f, 
                 NumberSigns -> {"-", "+"}, 
                 NumberPadding -> {"0", "0"}, 
                 SignPadding -> True];

output = OpenWrite["info.txt", FormatType -> OutputForm, PageWidth -> Infinity];
$Output = output;

n = 2.60152*10^-8 ;
Print[OutputForm[padIt[n, {15, 14}]]];

Now looking at the text file foo.txt shows that the number is written in text format.

enter image description here

share|improve this answer
add comment

You could use this

NumberForm[2.601519253*10^-8, {16, 16}, 
 ExponentFunction -> (If[-10 < # < 10, Null, #] &)]

(* 
0.0000000260151925
*)

Export into CSV format could be done as follows: Define a function

numFormat[y_] := 
 ToString@NumberForm[y, {16, 16}, 
   ExponentFunction -> (If[-10 < # < 10, Null, #] &)]

create a few values for demonstration purposes

numberStr = Map[numFormat, (RandomReal[1, 5])*10^-8]

export to file

    Export["test.csv", numberStr]

(* contents in file test.csv
0.0000000061627008
0.0000000052266995
0.0000000039287885
0.0000000098132366
0.0000000032460654
*)
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.