php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45983 Is interaction between strval() and "precision" setting in php.ini intended?
Submitted: 2008-09-03 13:32 UTC Modified: 2008-09-03 23:32 UTC
From: ivoras at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6 OS: FreeBSD
Private report: No CVE-ID: None
 [2008-09-03 13:32 UTC] ivoras at gmail dot com
Description:
------------
Calling strval() on certain floating point numbers (not all) on FreeBSD sometimes inexplicably truncates or rounds the result. Checked on both FreeBSD 6.3 and 7.0. Works fine in Linux.

Reproduce code:
---------------
<?php
$v = 4867.8;
echo strval($v);
?>


Expected result:
----------------
"4867.8"

Actual result:
--------------
"4867"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-03 13:42 UTC] ivoras at gmail dot com
Addition to the bug report: I tracked the issue down to the "precision" setting in php.ini. When set to "4", when strval() receives a number with 4 digits to the left of the decimal point, the output will only be a string og 4 digits. E.g. strval(1001.1) returns "1001". The documentation for "precision" setting says:

"""
  precision  integer
    The number of significant digits displayed in floating point numbers. 
"""

It doesn't mention strval() (and strval() manual page doesn't mention "precision") and it's a bit ambiguous.

(the behaviour is the same on Linux and FreeBSD).
 [2008-09-03 23:32 UTC] felipe@php.net
That is an expected behavior.
The strval() isn't required to you get this result, the echo statement, var_dump(), and etc will print the value according to the precision setting.

Thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 14:01:35 2025 UTC