php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #63673 Bug in number_format
Submitted: 2012-12-03 09:08 UTC Modified: 2012-12-03 09:10 UTC
From: lorenavva at gmail dot com Assigned:
Status: Not a bug Package: Testing related
PHP Version: Irrelevant OS: number_format
Private report: No CVE-ID: None
 [2012-12-03 09:08 UTC] 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);

				}
				
			}
		}	
	}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-03 09:10 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-12-03 09:10 UTC] aharvey@php.net
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.

.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat May 08 05:01:23 2021 UTC