PHP|BCMath: How to get bcscale value?
Asked Answered
F

2

8

How do I get the scale set in BCMath's bcscale() method?

Example:

bcscale(25);

How do I get the 25? Thanks!

Fibro answered 23/7, 2013 at 11:47 Comment(2)
Hi do you need to javascript or else PHP ?Government
@Government AS you can see from the title and the tags I'm refering to PHP.Fibro
H
1

This is fixed in PHP 7.3.

Calling bcscale(10) will return the previous scale and calling bcscale() will return the current scale.

source

Heteromorphic answered 24/1, 2018 at 4:8 Comment(0)
S
8

Update: As of PHP 7.3.0 you can just call the bcscale() function with no argument:

var_dump(bcscale()); // int(25)

Prior to PHP 7.3.0 you could at first try to read the bcmath.scale INI setting, which defaults to 0:

$scale = ini_get('bcmath.scale');

Since calling bcscale() didn't change the bcmath.scale INI setting, the only way to get the current scale factor was using a workaround like that:

$scale = strlen(bcsqrt('2')) - 2;
var_dump($scale); // int(25)
Spunk answered 8/11, 2013 at 16:1 Comment(0)
H
1

This is fixed in PHP 7.3.

Calling bcscale(10) will return the previous scale and calling bcscale() will return the current scale.

source

Heteromorphic answered 24/1, 2018 at 4:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.