Blogger Information
Blog 12
fans 0
comment 0
visits 6620
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
float 浮点型-php学习第四课
虎哥的学习日志
Original
588 people have browsed it

其它类型转换为浮点型

  1. 字符串类型转换为浮点型

    var_dump(floatval('123.32'));//123.32

  2. bool型转换为浮点型

    var_dump(floatval(true));//1

    var_dump(floatval(false));//0

  3. 整数转换为浮点型

    var_dump(floatval(12));//12

  4. 浮点数之间的比较

    $a=1.23456789;

    $b=1.23456780;

    $epsilion=0.00001;

    $epsilion_1=0.000000001;

    if(abs($a-$b)<$epsilion){

      echo '相等';

    }else{

     echo '不相等';

    }//此时输出相等

    if(abs($a-$b)<$epsilion_1){

      echo '相等';

    }else{

     echo '不相等';

    }//此时输出不相等

  5. 浮点型比较是判断差值在某一临界点,不能做绝对的相等或不相等判断

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post