bcadd php_bcadd - [ php中文手册 ] - 在线原生手册 - php中文网

!preg_match("/^\+?(\d+)(\.\d+)?$/",$Num2,$Tmp2)) return('0');// this is where the result is stored$Output=array();// remove ending zeroes from decimals and remove point$Dec1=isset($Tmp1[2])?rtrim(substr($Tmp1[2],1),'0'):'';$Dec2=isset($Tmp2[2])?rtrim(substr($Tmp2[2],1),'0'):'';// calculate the longest length of decimals$DLen=max(strlen($Dec1),strlen($Dec2));// if $Scale is null, automatically set it to the amount of decimal places for accuracyif($Scale==null)$Scale=$DLen;// remove leading zeroes and reverse the whole numbers, then append padded decimals on the end$Num1=strrev(ltrim($Tmp1[1],'0').str_pad($Dec1,$DLen,'0'));$Num2=strrev(ltrim($Tmp2[1],'0').str_pad($Dec2,$DLen,'0'));// calculate the longest length we need to process$MLen=max(strlen($Num1),strlen($Num2));// pad the two numbers so they are of equal length (both equal to $MLen)$Num1=str_pad($Num1,$MLen,'0');$Num2=str_pad($Num2,$MLen,'0');// process each digit, keep the ones, carry the tens (remainders)for($i=0;$i

if(isset($Output[$i]))$Sum+=$Output[$i];$Output[$i]=$Sum%10;

if($Sum>9)$Output[$i+1]=1;

}// convert the array to string and reverse it$Output=strrev(implode($Output));// substring the decimal digits from the result, pad if necessary (if $Scale > amount of actual decimals)

// next, since actual zero values can cause a problem with the substring values, if so, just simply give '0'

// next, append the decimal value, if $Scale is defined, and return result$Decimal=str_pad(substr($Output,-$DLen,$Scale),$Scale,'0');$Output=(($MLen-$DLen<1)?'0':substr($Output,0,-$DLen));$Output.=(($Scale>0)?".{$Decimal}":'');

return($Output);

}$A="5650175242.508133742";$B="308437806.831153821478770";printf("  Add(%s,%s);\r\n// %s\r\n\r\n",$A,$B,Add($A,$B));printf("BCAdd(%s,%s);\r\n// %s\r\n\r\n",$A,$B,BCAdd($A,$B));?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值