php / php/php-src

bcmath: strip leading/trailing zeros option (code is already there)

Offen
#19,135 1 Kommentar 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@SakiTakamachi arbeitet bereits daran.

Seit 15.7.2025.

Extension: bcmath Feature Status: Requires RFC
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

Description

@SakiTakamachi It seems that you're the one taking care of bcmath at least recently.

Would it be possible to add a flag to the bc* functions such as bcadd, bcmul and so on, that would strip the trailing and/or leading zeros from the results? Maybe even make it the default? At this time, bscale(10); bcadd('1', '2'); will produce the result '3.0000000000', which while correct, isn't really ideal.

Or at the very least, give public access to the already existing functions bc_rm_trailing_zeros() and _bc_rm_leading_zeros() ?

Ideally it would also have a flag to either keep or not the integer zero in values such as 0.1234 (so the strip leading zeros would either keep it or just return .1234).

I'm using bcmath very extensively in a project where performance matters and doing such sanitization in PHP itself is 1) a pain and 2) a performance sink. It would really help if that's something that could be handled directly by bcmath, which is otherwise a wondeful library that thankfully exists.

Thank you for your work on bcmath.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.