Re: [RFC] [Discussion] Support object type in BCMath

From: Date: Tue, 26 Mar 2024 12:07:51 +0000
Subject: Re: [RFC] [Discussion] Support object type in BCMath
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-122747@lists.php.net to get a copy of this message
On 2024-03-26 11:35, Saki Takamachi wrote:
**I immediately reflected the above two points in my RFC** :D
Thanks, looks good.
One more suggestion - might it be worth adding a format function to the new BcNum class? This would be similar to the existing number_format function, but would avoid the need to lose precision by converting to float first.
I came up with the following code, is it close to what you intended?
$num = BcNum::fromNumberFormat(1.2345, 5);
$num->value; // 1.23450
No, that's not quite what I meant - I meant more like the opposite:
$bcNum = new BcNum('1234567890123456789.23456789');
echo $bcNum->format(8, '.', ',') // 1,234,567,890,123,456,789.23456789
Maybe also worth providing a way to specify that all decimals should be printed, instead of just a fixed number of decimals.

« previous php.internals (#122747) next »