add numberWithCommas util#6
Conversation
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Ryan Martin <rmartin93@users.noreply.github.com>
PR ReviewOverall: Well-structured addition. Code follows repo conventions and implements a useful utility function. ✅ Strengths
🔍 Issues FoundBug: Negative number handling (numbers.ts:15) numberWithCommas(-1234.56, 2) // Returns "-,1234.56" ❌Fix: // Handle negative sign
const isNegative = integerPart.startsWith("-");
const absoluteInt = isNegative ? integerPart.slice(1) : integerPart;
const withCommas = absoluteInt.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return (isNegative ? "-" : "") + (decimalPart !== undefined ? `${withCommas}.${decimalPart}` : withCommas);💡 RecommendationsAdd edge case tests - Consider these scenarios:
Add JSDoc example: /**
* Format number with comma separators and optional decimal places
* @example numberWithCommas(1234.567, 2) // "1,234.57"
*/📊 Assessment
Recommendation: Fix negative number handling before merge, then LGTM. |
|
@claude can you fix the negative number issue? |
|
Claude finished @rmartin93's task in 1m 1s —— View job Negative number bug fixed ✓
Summary: Fixed negative number handling by extracting the negative sign before applying comma regex, then prepending it back to the result. Examples of fixed behavior:
| |
Co-authored-by: Ryan Martin <rmartin93@users.noreply.github.com>
PR Review: numberWithCommas utilityStrengths
Potential Issues1. Type coercion bug (ts/utilities/numbers.ts:16) decimalPart !== undefined ? `${withCommas}.${decimalPart}` : withCommasIssue: split() returns string[] | undefined for second element, but checking !== undefined. Empty string after decimal (e.g., "5.") would pass this check incorrectly. Fix: Check decimalPart != null or restructure logic. 2. Inconsistent decimal handling
This may be intentional, but consider documenting behavior. Edge Cases to ConsiderTest these scenarios:
SuggestionsAdd usage examples in comments: // Format number with comma separators and optional decimal places
// Examples:
// numberWithCommas(1234567) = "1,234,567"
// numberWithCommas(1234.5, 2) = "1,234.50"
// numberWithCommas(-9876543.21) = "-9,876,543.21"
export function numberWithCommas(num: number, decimalPlaces?: number): string {Consider renaming to match existing patterns:
Overall AssessmentCode Quality: 8/10 - Clean, readable, follows repo conventions Recommendation: Approve with minor fixFix the decimalPart !== undefined check on line 16, then merge. Great addition to the utilities library. Review automated via Claude Code |
Adds TypeScript utility function for formatting numbers with comma separators
Closes #4
🤖 Generated with Claude Code