gpt4 book ai didi

decimal - phpexcel读取excel文件十进制数读取不正确

转载 作者:行者123 更新时间:2023-12-01 05:14:39 24 4
gpt4 key购买 nike

我在 .xlsx 文件的单元格中得到了值“9,2”(荷兰语表示法“9.2”),该单元格具有“通用”数字格式。此外,您还可以查看公式的上方栏中的值显示“9,2”,当我使用 PHPExcel 使用 ->getValue() 读取此单元格时,我得到“9,199999999999999”。

这是我的代码:

$oPhpReader = PHPExcel_IOFactory::createReader($sFileType);
$aWorksheetNames = $oPhpReader->listWorksheetNames($sFileName);
$oPhpReader->setReadDataOnly(true);
$oPhpReader->setLoadSheetsOnly($aWorksheetNames[0]);
$oPhpExcel = $oPhpReader->load($sFileName);
$oWorksheet = $oPhpExcel->getActiveSheet();
$oCell = $oWorksheet->getCellByColumnAndRow($iCol,$iRow);
$sTempValue = $oCell->getValue();

最佳答案

这就是我现在解决问题的方法。虽然我不认为这是一个非常巧妙的解决方案,但它可能是唯一的方法。

我只是想我永远不会得到超过 12 位的数字,只有当 PHPExcel 出错时。所以我使用 number_format 将所有浮点数四舍五入到 12 位:

if ((is_numeric($sTempValue))&&(strpos($sTempValue,'.')))
{
$sTempValue = rtrim(rtrim(number_format($sTempValue,12,',',''),'0'),',');
}

关于decimal - phpexcel读取excel文件十进制数读取不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21935144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com