note 129085 added to function.printf
| From: | anonymous at main dot php dot net | Date: | Sun, 03 Dec 2023 16:33:48 +0000 |
| Subject: | note 129085 added to function.printf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221039@lists.php.net to get a copy of this message | ||
When using the
<?= ?> syntax to print out the result, be aware that printf()
returns the length of string after echoing out the result, so the following will happen:
Source code:
```
<p>Total: <?= printf('%.2f', 1+2) ?></p>
```
will result in:
Total: 3.004
when it should be:
Total: 3.00
Use sprintf() for using <?= ?> syntax, which returns the formatted string itself.
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 2001:e68:541a:68ab:70d1:a4f8:2b90:194e)
----
Manual Page -- https://php.net/manual/en/function.printf.php
Edit -- https://main.php.net/note/edit/129085
Del: integrated -- https://main.php.net/note/delete/129085/integrated
Del: useless -- https://main.php.net/note/delete/129085/useless
Del: bad code -- https://main.php.net/note/delete/129085/bad+code
Del: spam -- https://main.php.net/note/delete/129085/spam
Del: non-english -- https://main.php.net/note/delete/129085/non-english
Del: in docs -- https://main.php.net/note/delete/129085/in+docs
Del: other reasons-- https://main.php.net/note/delete/129085
Reject -- https://main.php.net/note/reject/129085
Search -- https://main.php.net/manage/user-notes.php