note 41621 added to function.sprintf
| From: | tobiasatsilverxnetdotde at rn2 dot php dot net | Date: | Fri, 16 Apr 2004 23:09:18 +0000 |
| Subject: | note 41621 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68228@lists.php.net to get a copy of this message | ||
Regarding the previous posting:
I just wanted to give an explanation. This should be because the float to string / integer to string
conversion (you are using a string, multiplying it with a float value what php automatically causes
to convert the string to a float value). This is a general "problem" (or not), but not
that hard to explain.
Where an integer or float starts with 0, in a string it does obviously with 1. So if you are using a
string your value will increase by one (You started with a string, so it does not increase but
contain the real result. If you start using a float value by not using '' around the
value, you have to output the float value as well. This is just the PHP conversion.)
Try putting
$x = strval( $x );
after
$x = $x * 100;
and using your example again. You will see that the output will change to 13664 = 13664 because of
the general string conversion. It seems that PHP is converting a float to a string by inceasing by
one. By doing the same with intval instead of strval the output changes to 13663 = 13663.
! sprintf seems to behave wrong when using the conversation to an integer value and NOT doing the
conversation at all. So use intval to convert to an integer value or strval to convert to a string
value BEFORE using sprintf. This should be solving the problems.
----
Manual Page -- http://www.php.net/manual/en/function.sprintf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41621
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41621&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41621&report=yes
Search -- http://master.php.net/manage/user-notes.php