0

when i set a cell value like this

->setCellValue('O' . $currentRow, 12000000000000111702)

or

->setCellValue('O' . $currentRow, "12000000000000111702")

it is generating values 1.2E+19 i.e 12000000000000000000 can anyone tell me the reason ?

dnagirl
  • 19,254
  • 12
  • 74
  • 113
hemc4
  • 1,583
  • 2
  • 16
  • 31
  • I think this is an Excel problem, not a php problem. Probably it's the formatting of the cell. When you're dealing with such huge numbers, it's "normal" to lose accuracy. Usually Excel works to about 15 significant figures or so – GarethL Jan 15 '13 at 12:50
  • In fact: If I copy/paste the number 12000000000000111702 into an Excel cell, it changes it automatically to 12000000000000100000 – GarethL Jan 15 '13 at 12:52
  • http://stackoverflow.com/questions/8647125/using-long-int-in-php – Shomz Jan 15 '13 at 12:55
  • if you put the same number into Excel directly, it will be truncated to 0.120000000000001. So PHP will not be losing your Excel users any more precision than they would lose anyway. – dnagirl Jan 15 '13 at 12:55

1 Answers1

2

If you need this value to be retained exactly "as is" rather than converted to a float (because it's too big for a PHP int), then you'll need to set the value explicitly as a string using

->setCellValueExplicit('O' . $currentRow, "12000000000000111702", PHPExcel_Cell_DataType::TYPE_STRING)

You don't actually need to specify PHPExcel_Cell_DataType::TYPE_STRING because setCellValueExplicit() defaults to that anyway.

Mark Baker
  • 199,760
  • 28
  • 325
  • 373