查看: 6556|回复: 0
打印 上一主题 下一主题

PHP函数bcdiv()高精度数学函数

[复制链接]
跳转到指定楼层
1#
发表于 2008-3-31 15:21:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
bcdiv
(PHP 4, PHP 5)

bcdiv — Divide two arbitrary precision numbers

说明
string bcdiv ( string $left_operand, string $right_operand [, int $scale] )

Divides the left_operand by the right_operand.

参数

left_operand
The left operand, as a string.

right_operand
The right operand, as a string.

scale
This optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().


返回值
Returns the result of the division as a string, or NULL if right_operand is 0.

范例
例 312. bcdiv() example

<?php

echo bcdiv('105', '6.55957', 3);  // 16.007

?>


参见
bcmul()





User Contributed Notes bcdiv
Gautam
29-Aug-2007 10:56
<?php
//converting in to required precision of decimal points
$result= bcdiv(89.99999999997,2.57865741235478,2);
echo "$result";  // 34.90 result with 2 decimal points
?>
cristianDOTzuddas]NOSPAM[gmailDOTcom
24-Jul-2005 08:10
Decimal to binary conversion, using BC Math.
Note: this function is VERY slow if the decimal number is too big!

<?
function bc_decbin($dec_str) {
    if (strlen($dec_str)>0) {
        $bin_str = '';
        do {
            if (((int)$dec_str[strlen($dec_str)-1] % 2) === 0)
                $bin_str .= '0';
            else
                $bin_str .= '1';
            
            $dec_str = bcdiv($dec_str, '2');
        } while ($dec_str!='0');
        
        return strrev($bin_str);
    }
    else
        return null;
}
?>
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表