php / php/php-src

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

Đang mở
#19,135 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@SakiTakamachi đang làm issue này rồi.

Từ ngày 15/7/2025.

Extension: bcmath Feature Status: Requires RFC
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.