Doc #63673 [Opn->Nab]: Bug in number_format

From: Date: Mon, 03 Dec 2012 09:10:16 +0000
Subject: Doc #63673 [Opn->Nab]: Bug in number_format
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9247@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63673&edit=1 ID: 63673 Updated by: aharvey@php.net Reported by: lorenavva at gmail dot com Summary: Bug in number_format -Status: Open +Status: Not a bug Type: Documentation Problem Package: Testing related Operating System: number_format PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://www.floating-point-gui.de/ Thank you for your interest in PHP. . Previous Comments: ------------------------------------------------------------------------ [2012-12-03 09:08:32] lorenavva at gmail dot com Description: ------------ Dears developer: I have the next problem with function number_format. I understand thar number_format do a high round. I am write one case where there is bug: Original Number --> Number with round 2462.055--2462.05 However in this case there isn´t bug: Original Number --> Number with round 3707.055--3707.06 Could you help me, please? Best Regards --- From manual page: http://www.php.net/function.number-format#refsect1-function.number-format-description --- Test script: --------------- $sql = "SELECT * FROM access_subv_abona WHERE borrado = 0"; $rs_abonada =mysql_query($sql); if($rs_abonada) { if(mysql_num_rows($rs_abonada)>0) { for($i=0; $i<mysql_num_rows($rs_abonada);$i++) { if(mysql_result($rs_abonada,$i, "subvencion_concedida") >0){ $datos_expediente=consultaSimple("expedientes","id=".intval(mysql_result($rs_abonada,$i,"id_expediente"))." and borrado=0"); $subvencion_total= $datos_expediente['subvencion_concedida']; $subvencion_abonada = number_format(0.5* $subvencion_total,2,'.','')+number_format(0.25* $subvencion_total,2,'.',''); $exp_actualizado=array(); $subvencion_abonada_bd= mysql_result($rs_abonada,$i,"subvencion_abonada"); $ajuste_abono=($subvencion_abonada_bd- $subvencion_abonada); print_r((0.25* $subvencion_total)."--".number_format((0.25* $subvencion_total),2,'.','')."<br>"); print_r($subvencion_abonada_bd."--".$subvencion_abonada."<br>"); print_r($datos_expediente['name']."-->".$ajuste_abono); } } } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63673&edit=1

« previous php.doc.bugs (#9247) next »