Skip to content

Commit

Permalink
v1.1.8
Browse files Browse the repository at this point in the history
* Fix `bcdiv()` by zero and errors in PHP 8.1
  • Loading branch information
ve3 committed Dec 8, 2021
1 parent 7071d5f commit 0d837f2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Rundiz/Number/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Number class.
*
* @package Number
* @version 1.1.7
* @version 1.1.8
* @author Vee W.
* @license http://opensource.org/licenses/MIT
*
Expand Down Expand Up @@ -36,14 +36,14 @@ class Number
'GB' => 1000000000,
'TiB' => 1099511627776,
'TB' => 1000000000000,
'PiB' => 1125899906842624,
'PB' => 1000000000000000,
'EiB' => 1152921504606846976,
'EB' => 1000000000000000000,
'ZiB' => 1180591620717411303424,
'ZB' => 1000000000000000000000,
'YiB' => 1208925819614629174706176,
'YB' => 1000000000000000000000000,
'PiB' => '1125899906842624',// use string to prevent division by zero because int number is larger than PHP_INT_MAX.
'PB' => '1000000000000000',
'EiB' => '1152921504606846976',
'EB' => '1000000000000000000',
'ZiB' => '1180591620717411303424',
'ZB' => '1000000000000000000000',
'YiB' => '1208925819614629174706176',
'YB' => '1000000000000000000000000',
);


Expand Down Expand Up @@ -104,17 +104,18 @@ public function convertNumber($num, $language = 'Thai')
/**
* convert file size from bytes to the unit you specified or automatically detect.
*
* @param integer $size file size in bytes only.
* @param int|float|string $size file size in bytes only.
* @param string $unit unit you want to convert. accepted values are AUTO, B, KB, KiB, ... more please refer to byte_units property.
* @param integer $decimal number of decimal.
* @return mixed return converted file size as string if success, return false if failed to convert.
* @return mixed return converted file size as string if success, return `false` if failed to convert.
*/
public function fromBytes($size, $unit = 'AUTO', $decimal = 2)
{
if (!is_numeric($size)) {
return false;
}
$size = (string) $size;

$size = sprintf('%f', floatval($size));

if ($unit == null) {
$unit = 'AUTO';
Expand Down

0 comments on commit 0d837f2

Please sign in to comment.