无需言 做自己 业 ,精于勤 荒于嬉.

Math 函数 round 对浮点数进行四舍五入

发表日期:2021-07-01 08:56:08 | 来源: | 分类:Math 函数

      示例1
<?php 
var_dump(round(3.4));
var_dump(round(3.5));
var_dump(round(3.6));
var_dump(round(3.6, 0));
var_dump(round(5.045, 2));
var_dump(round(5.055, 2));
var_dump(round(345, -2));
var_dump(round(345, -3));
var_dump(round(678, -2));
var_dump(round(678, -3));
?>

      示例2
<?php 
$number = 135.79;
var_dump(round($number, 3));
var_dump(round($number, 2));
var_dump(round($number, 1));
var_dump(round($number, 0));
var_dump(round($number, -1));
var_dump(round($number, -2));
var_dump(round($number, -3));
?>

      示例3
<?php 
echo 'Rounding modes with 9.5' . PHP_EOL;
var_dump(round(9.5, 0, PHP_ROUND_HALF_UP));
var_dump(round(9.5, 0, PHP_ROUND_HALF_DOWN));
var_dump(round(9.5, 0, PHP_ROUND_HALF_EVEN));
var_dump(round(9.5, 0, PHP_ROUND_HALF_ODD));
echo PHP_EOL;
echo 'Rounding modes with 8.5' . PHP_EOL;
var_dump(round(8.5, 0, PHP_ROUND_HALF_UP));
var_dump(round(8.5, 0, PHP_ROUND_HALF_DOWN));
var_dump(round(8.5, 0, PHP_ROUND_HALF_EVEN));
var_dump(round(8.5, 0, PHP_ROUND_HALF_ODD));
?>

      示例4
<?php 
echo 'Using PHP_ROUND_HALF_UP with 1 decimal digit precision' . PHP_EOL;
var_dump(round( 1.55, 1, PHP_ROUND_HALF_UP));
var_dump(round(-1.55, 1, PHP_ROUND_HALF_UP));
echo PHP_EOL;
echo 'Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision' . PHP_EOL;
var_dump(round( 1.55, 1, PHP_ROUND_HALF_DOWN));
var_dump(round(-1.55, 1, PHP_ROUND_HALF_DOWN));
echo PHP_EOL;
echo 'Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision' . PHP_EOL;
var_dump(round( 1.55, 1, PHP_ROUND_HALF_EVEN));
var_dump(round(-1.55, 1, PHP_ROUND_HALF_EVEN));
echo PHP_EOL;
echo 'Using PHP_ROUND_HALF_ODD with 1 decimal digit precision' . PHP_EOL;
var_dump(round( 1.55, 1, PHP_ROUND_HALF_ODD));
var_dump(round(-1.55, 1, PHP_ROUND_HALF_ODD));
?>

阅读全文 »

Math 函数 hexdec 十六进制转换为十进制

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

      示例1
<?php 
var_dump(hexdec("See"));
var_dump(hexdec("ee"));
// both print "int(238)"var_dump(hexdec("that"));
 // print "int(10)"var_dump(hexdec("a0"));
 // print "int(160)"?>

阅读全文 »

Math 函数 getrandmax 显示随机数最大的可能值

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

getrandmax

(PHP 4, PHP 5, PHP 7, PHP 8)

getrandmax显示随机数最大的可能值

说明

getrandmax(): int

返回调用 rand() 可能返回的最大值。

返回值

rand() 返回 随机数可能返回的最大值

参见

阅读全文 »

Math 函数 floor 舍去法取整

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

      示例1
<?php 
echo floor(4.3);
   // 4echo floor(9.999);
 // 9echo floor(-3.14);
 // -4?>

阅读全文 »

Math 函数 hypot 计算一直角三角形的斜边长度

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

hypot

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

hypot 计算一直角三角形的斜边长度

说明

hypot(float $x, float $y): float

hypot() 函数将会跟据直角三角形的两直解边长度 xy 计算其斜边的长度。或者是从标点 (x, y) 到原点的距离。该函数的算法等同于 sqrt(x*x + y*y)

参数

x

第一条边的长度

y

第二条边的长度

返回值

计算斜边的长度

阅读全文 »

Math 函数 intdiv 对除法结果取整

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

      示例1
<?php 
var_dump(intdiv(3, 2));
var_dump(intdiv(-3, 2));
var_dump(intdiv(3, -2));
var_dump(intdiv(-3, -2));
var_dump(intdiv(PHP_INT_MAX, PHP_INT_MAX));
var_dump(intdiv(PHP_INT_MIN, PHP_INT_MIN));
var_dump(intdiv(PHP_INT_MIN, -1));
var_dump(intdiv(1, 0));
?>

阅读全文 »

Math 函数 is_finite 判断是否为有限值

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

is_finite

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

is_finite判断是否为有限值

说明

is_finite(float $val): bool

检查 val 是否是是本机平台上浮点数所允许范围中的一个合法的有限值。

参数

val

要检查的值

返回值

如果 val 是本机平台上 PHP 浮点数所允许范围中的一个合法的有限值,则返回 true

参见

阅读全文 »

Math 函数 fmod 返回除法的浮点数余数

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

      示例1
<?php 
$x = 5.7;
$y = 1.3;
$r = fmod($x, $y);
// $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7?>

阅读全文 »

Math 函数 is_infinite 判断是否为无限值

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

is_infinite

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

is_infinite判断是否为无限值

说明

is_infinite(float $val): bool

如果 val 为无穷大(正的或负的),例如 log(0) 的结果或者任何超出本平台的浮点数范围的值,则返回 true

参数

val

要检查的值

返回值

如果 val 为无穷大返回 true,否则返回 false

参见

阅读全文 »

Math 函数 lcg_value 组合线性同余发生器

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

lcg_value

(PHP 4, PHP 5, PHP 7, PHP 8)

lcg_value组合线性同余发生器

说明

lcg_value(): float

lcg_value() 返回范围为 (0, 1) 的一个伪随机数。本函数组合了周期为 2^31 - 85 和 2^31 - 249 的两个同余发生器。本函数的周期等于这两个素数的乘积。

返回值

范围为 (0, 1) 的伪随机数。

参见

阅读全文 »

Math 函数 log1p 返回 log(1 + number),甚至当 number 的值接近零也能计算出准确结果

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

log1p

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

log1p 返回 log(1 + number),甚至当 number 的值接近零也能计算出准确结果

说明

log1p(float $number): float

log1p() 返回 log(1 + number),甚至当 number 的值接近零也能计算出准确结果。 log() might only return log(1) in this case due to lack of precision.

参数

number

要处理的参数

返回值

log(1 + number)

更新日志

版本 说明
5.3.0 此函数在所有平台上均可用

参见

  • expm1() - 返回 exp(number) - 1,甚至当 number 的值接近零也能计算出准确结果
  • log() - 自然对数
  • log10() - 以 10 为底的对数

阅读全文 »

Math 函数 log 自然对数

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

log

(PHP 4, PHP 5, PHP 7, PHP 8)

log自然对数

说明

log(float $arg, float $base = M_E): float

如果指定了可选的参数 baselog() 返回 logbase arg,否则 log() 返回参数 arg 的自然对数。

参数

arg

要计算对数的值

base

The optional logarithmic base to use (defaults to 'e' and so to the natural logarithm).

返回值

返回 logbase arg,或者它的自然对数。

更新日志

版本 说明
4.3.0 可选参数 base可用。 你可以计算任意以 b 为底 n 的对数,但其实使用的是数学等式:logb(n) = log(n)/log(b),其中 log 是自然对数。

参见

  • log10() - 以 10 为底的对数
  • exp() - 计算 e 的指数
  • pow() - 指数表达式

阅读全文 »

Math 函数 is_nan 判断是否为合法数值

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

      示例1
<?php 
// Invalid calculation, will return a // NaN value$nan = acos(8);
var_dump($nan, is_nan($nan));
?>

阅读全文 »

Math 函数 max 找出最大值

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

      示例1
<?php 
echo max(1, 3, 5, 6, 7);
  // 7echo max(array(2, 4, 5));
 // 5// When 'hello' is cast as integer it will be 0. Both the parameters are equally// long, so the order they are given in determines the resultecho max(0, 'hello');
     // 0echo max('hello', 0);
     // helloecho max('42', 3);
 // '42'// Here 0 > -1, so 'hello' is the return value.echo max(-1, 'hello');
    // hello// With multiple arrays of different lengths, max returns the longest$val = max(array(2, 2, 2), array(1, 1, 1, 1));
 // array(1, 1, 1, 1)// 对多个数组,max 从左向右比较。   // 因此在本例中:2 == 2,但 4 < 5$val = max(array(2, 4, 8), array(2, 5, 7));
 // array(2, 5, 7)// 如果同时给出数组和非数组作为参数,则总是将数组视为   // 最大值返回$val = max('string', array(2, 5, 7), 42);
   // array(2, 5, 7)?>

阅读全文 »

Math 函数 log10 以 10 为底的对数

发表日期:2021-07-01 08:56:07 | 来源: | 分类:Math 函数

log10

(PHP 4, PHP 5, PHP 7, PHP 8)

log10以 10 为底的对数

说明

log10(float $arg): float

返回参数 arg 以 10 为底的对数。

参数

arg

要处理的参数

返回值

arg 以 10 为底的对数。

参见

阅读全文 »

Math 函数 atan 反正切

发表日期:2021-07-01 08:56:06 | 来源: | 分类:Math 函数

atan

(PHP 4, PHP 5, PHP 7, PHP 8)

atan反正切

说明

atan(float $arg): float

返回 arg 的反正切值,单位是弧度。atan()tan() 的反函数,它的意思是在 atan() 范围里的每个值都是 a==tan(atan(a))

参数

arg

要处理的参数

返回值

arg 的反正切弧度。

参见

阅读全文 »

Math 函数 acosh 反双曲余弦

发表日期:2021-07-01 08:56:06 | 来源: | 分类:Math 函数

acosh

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

acosh反双曲余弦

说明

acosh(float $arg): float

返回 arg 的反双曲余弦值,即,其双曲余弦为 arg 的那个值。

参数

arg

要处理的值

返回值

The inverse hyperbolic cosine of arg

更新日志

版本 说明
5.3.0 This function is now available on all platforms

参见

阅读全文 »

Math 函数 base_convert 在任意进制之间转换数字

发表日期:2021-07-01 08:56:06 | 来源: | 分类:Math 函数

      示例1
<?php 
$hexadecimal = 'A37334';
echo base_convert($hexadecimal, 16, 2);
?>

阅读全文 »

Math 函数 bindec 二进制转换为十进制

发表日期:2021-07-01 08:56:06 | 来源: | 分类:Math 函数

      示例1
<?php 
echo bindec('110011') . "\n";
echo bindec('000110011') . "\n";
echo bindec('111');
?>

      示例2
<?php 
/* * The lesson from this example is in the output * rather than the PHP code itself. */
$magnitude_lower = pow(2, (PHP_INT_SIZE * 8) - 2);
p($magnitude_lower - 1);
p($magnitude_lower, 'See the rollover?  Watch it next time around...');
p(PHP_INT_MAX, 'PHP_INT_MAX');
p(~PHP_INT_MAX, 'interpreted to be one more than PHP_INT_MAX');
if (PHP_INT_SIZE == 4) {
    $note = 'interpreted to be the largest unsigned integer';
}
 else {
    $note = 'interpreted to be the largest unsigned integer              (18446744073709551615) but skewed by float precision';
}
p(-1, $note);
function p($input, $note = '') {
    echo "input:        $input\n";
    $format = '%0' . (PHP_INT_SIZE * 8) . 'b';
    $bin = sprintf($format, $input);
    echo "binary:       $bin\n";
    ini_set('precision', 20);
  // For readability on 64 bit boxes.    $dec = bindec($bin);
    echo 'bindec():     ' . $dec . "\n";
    if ($note) {
        echo "NOTE:         $note\n";
    }
    echo "\n";
}
?>

阅读全文 »

Math 函数 acos 反余弦

发表日期:2021-07-01 08:56:06 | 来源: | 分类:Math 函数

acos

(PHP 4, PHP 5, PHP 7, PHP 8)

acos反余弦

说明

acos(float $arg): float

返回 arg 的反余弦值,单位是弧度。acos()cos() 的反函数,它的意思是在 acos() 范围里的每个值都是 a==cos(acos(a))

参数

arg

要处理的参数

返回值

arg 的反余弦弧度。

参见

阅读全文 »

全部博文(1580)
集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。