note 128791 added to function.intdiv
| From: | chimerawd at main dot php dot net | Date: | Fri, 11 Aug 2023 14:29:17 +0000 |
| Subject: | note 128791 added to function.intdiv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220751@lists.php.net to get a copy of this message | ||
If you're having trouble calculating averages using numberic values stored in variables, you
can cast each value to an (int) each step of the process, which should give you the result you want.
If you are round the result you need to cast the rounded result to an (int) also.
$sumAge = (int) $avgData['sumAge'];
$sumQty = (int) $avgData['sumQty'];
$avgData['avg'] = (int) round( $sumAge / $sumQty );
There may be better ways to do this, however this is the way I found works on PHP version 5.6.40 and
higher
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 180.150.55.102)
----
Manual Page -- https://php.net/manual/en/function.intdiv.php
Edit -- https://main.php.net/note/edit/128791
Del: integrated -- https://main.php.net/note/delete/128791/integrated
Del: useless -- https://main.php.net/note/delete/128791/useless
Del: bad code -- https://main.php.net/note/delete/128791/bad+code
Del: spam -- https://main.php.net/note/delete/128791/spam
Del: non-english -- https://main.php.net/note/delete/128791/non-english
Del: in docs -- https://main.php.net/note/delete/128791/in+docs
Del: other reasons-- https://main.php.net/note/delete/128791
Reject -- https://main.php.net/note/reject/128791
Search -- https://main.php.net/manage/user-notes.php