2

Writing floats to a CSV writes some of them like this: 2.0628800997782577e-05

c = csv.writer(open(file, "wb"))
c.writerow([var1, var2])    

What I've tried:

  • I have already tried var1**8 following other answers on StackOverflow, but this simply raises them to the power of 8.
  • I have also tried Decimal(var1), but this does not suppress the scientific notation.

This makes it difficult to process the output in excel afterwards as it's recognized as text and not a number. How can I print it in non-scientific, decimal notation?

Zach
  • 4,624
  • 13
  • 43
  • 60

2 Answers2

5
'%f' % your_var

Or to control the precision:

'%0.10f' % your_var
mVChr
  • 49,587
  • 11
  • 107
  • 104
4

Use string formatting:

c.writerow(['{:f}'.format(var) for var in (var1, var2)]
millimoose
  • 39,073
  • 9
  • 82
  • 134