简体   繁体   English

PHP | BCMath:如何获得bcscale值?

[英]PHP|BCMath: How to get bcscale value?

How do I get the scale set in BCMath's bcscale() method? 如何在BCMath的bcscale()方法中设置比例?

Example: 例:

bcscale(25);

How do I get the 25? 我怎么得到25? Thanks! 谢谢!

You can't. 你不能。 Currently you can get only the bcmath.scale INI setting, which defaults to 0: 目前,您只能获得bcmath.scale INI设置,默认为0:

print ini_get('bcmath.scale');

Unfortunatelly bcscale() didn't change the bcmath.scale INI setting and you can't get the scale factor without a workaround like that: 不幸的是, bcscale()没有改变bcmath.scale INI设置,如果没有像这样的解决方法,你无法获得比例因子:

bcscale(25);

function get_bcscale()
{
    $sqrt = bcsqrt('2');
    return strlen(substr($sqrt, strpos($sqrt, '.') + 1));
}

var_dump(get_bcscale()); # int(25)

This is fixed in PHP 7.3. 这在PHP 7.3中得到修复。

Calling bcscale(10) will return the previous scale and calling bcscale() will return the current scale. 调用bcscale(10)将返回先前的比例,并且调用bcscale()将返回当前比例。

source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM