PHPmanual中說(shuō):以十進(jìn)制能夠精確表示的有理數(shù)如0.1或0.7,無(wú)論有多少尾數(shù)都不能被內(nèi)部所使用的二進(jìn)制精確表示,因此不能在不丟失一點(diǎn)點(diǎn)精度的情況下轉(zhuǎn)換為二進(jìn)制的格式。//example1$float=(0.1+0.7)*10;echo(integer)$float;//7echofloor($float);//7//example2echo(integer)(1.5+1.5);//3echofloor(1.5+1.5);//3//example3echo(integer)(0.5*10);//5echofloor(0.5*10);//5為什么在例子2和例子3中,浮點(diǎn)數(shù)的加和乘運(yùn)算能夠保全精度呢?
關(guān)于PHP浮點(diǎn)數(shù)精度問(wèn)題
皈依舞
2019-04-14 09:52:37