Skip to content

Conversation

@samdark
Copy link
Member

@samdark samdark commented Jan 8, 2026

Q A
Is bugfix?
New feature? ✔️
Breaks BC?

@samdark samdark requested review from a team and Copilot January 8, 2026 20:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new NumericHelper::trimDecimalZeros() method that removes trailing zeros from the decimal part of numeric strings. The implementation handles various edge cases including null values, empty strings, negative numbers, and numbers without decimal parts.

  • Adds trimDecimalZeros() static method to NumericHelper class
  • Includes comprehensive test coverage with 10 test cases
  • Updates documentation comment style for existing method

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/NumericHelper.php Adds the new trimDecimalZeros() method with documentation, also fixes hyphenation in existing docblock
tests/NumericHelperTest.php Adds test data provider and test method for the new functionality
CHANGELOG.md Documents the new feature in the 2.7.1 release notes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI commented Jan 8, 2026

@samdark I've opened a new pull request, #157, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Jan 8, 2026

@samdark I've opened a new pull request, #158, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits January 9, 2026 01:03
Co-authored-by: samdark <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: samdark <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
samdark and others added 6 commits January 11, 2026 14:10
Co-authored-by: Sergei Tigrov <[email protected]>
diff --git c/src/NumericHelper.php i/src/NumericHelper.php
index c602ede..2506fde 100644
--- c/src/NumericHelper.php
+++ i/src/NumericHelper.php
@@ -16,9 +16,6 @@ use function is_numeric;
 use function is_scalar;
 use function preg_match;
 use function preg_replace;
-use function rtrim;
-use function str_contains;
-use function str_ends_with;
 use function str_replace;
 use function substr;

@@ -176,7 +173,7 @@ final class NumericHelper
      * containing a decimal part.
      *
      * @return string|null The input string with trailing decimal zeros (and a trailing decimal
-     * separator, if any) removed, or `null` if the input was `null`.
+     * separator, if any) removed, or `null` if the input was `null` or an empty string.
      */
     public static function trimDecimalZeros(?string $value): ?string
     {
diff --git c/src/NumericHelper.php i/src/NumericHelper.php
index 2506fde..d1c388b 100644
--- c/src/NumericHelper.php
+++ i/src/NumericHelper.php
@@ -186,16 +186,26 @@ final class NumericHelper
             return null;
         }

-        if (!str_contains($value, '.')) {
-            return $value;
-        }
-        /** @psalm-suppress PossiblyNullArgument */
-        $value = rtrim($value, '0');
-
-        if (!str_ends_with($value, '.')) {
+        $decimalPosition = strpos($value, '.');
+        if ($decimalPosition === false) {
             return $value;
         }

-        return substr($value, 0, -1);
+        $length = strlen($value);
+        $index = $length - 1;
+
+        while ($index > $decimalPosition && $value[$index] === '0') {
+            $index--;
+        }
+
+        if ($index === $length - 1) {
+            return $value;
+        }
+
+        if ($index === $decimalPosition) {
+            return substr($value, 0, $decimalPosition);
+        }
+
+        return substr($value, 0, $index + 1);
     }
 }
@samdark samdark requested review from Tigrov, Copilot and vjik January 13, 2026 00:25
@samdark samdark added the status:code review The pull request needs review. label Jan 13, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add info to readme

@samdark samdark requested a review from vjik January 16, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants