Hello all,

Would adding a bcgetopts(): int and a bcsetopts(int $opts): void calls be useful?

At this time there's no way to influence bcmath's behavior other than bcscale().

An example of option that could be configurable through this mechanism would be automatic removal of trailing / leading zeros in the results returned by bcmath.

bcscale(10);
echo bcadd('1', '2');
result: 3.0000000

 If we could tell bcmath to strip the trailing zeros by calling

bcsetopts(bcgetopts() | BC_STRIP_TRAILING_ZEROS));


, the result should be just '3'.



Some options I could think of:
BC_STRIP_TRAILING_ZEROS
BC_STRIP_LEADING_ZEROS
BC_STRIP_ZERO_INTEGER (so instead of returning 0.5, it would just return .5)


The actual code to strip the trailing/leading zeros seems to already be in the library, just not exposed to the API (bc_rm_*() in libbcmath/src/rmzero.c).

I'm using PHP's bcmath extensively in a performance-sensitive application and sanitizing the results in PHP is a performance sink that could be avoided this way.

Thank you for your attention.

Reply via email to