format percentage test#2
Conversation
Codoki PR ReviewSummary: Fix percentage formatting logic, ensure correct input handling and output. Issues (Medium)
Showing up to 2 medium issue(s). See inline suggestions for more details. Key Feedback (click to expand)
Confidence: 4/5 — Looks good; minor fixes (2 medium) React with 👍 or 👎 if you found this review useful. |
Codoki PR ReviewAlmost there! 🚀 We’ll run this review once you’re connected to Codoki. Quick setup (≈2 minutes):
What you’ll get:
Need help? info@codoki.ai |
| */ | ||
| public static function formatPercentage($number, $precision = 2, $locale = null) | ||
| { | ||
| if (!is_numeric($number)) { |
There was a problem hiding this comment.
🔷 Medium: The current input validation only checks if the input is numeric. Consider throwing an exception for non-numeric input to align with the class's error-handling practices and provide clearer feedback to the caller.
| $formatter = new NumberFormatter($locale ?? app()->getLocale(), NumberFormatter::PERCENT); | ||
| $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $precision); | ||
|
|
||
| return $formatter->format($number / 100); |
There was a problem hiding this comment.
🔷 Medium: The division by 100 assumes the input is a percentage value (e.g., 12.34 becomes 0.1234). Ensure this behavior is documented and consistent with the method's intent.
| return $formatter->format($number / 100); | |
| return $formatter->format($number); |
This PR adds a new formatPercentage method to the Number class that allows formatting numbers as percentages with customizable precision and locale support.