Skip to content

refactor: rename to FormatFloatComma, document rounding vs truncation - #148

Open
walle250ai wants to merge 3 commits into
dustin:masterfrom
walle250ai:feature/rename-to-format-float-comma
Open

refactor: rename to FormatFloatComma, document rounding vs truncation#148
walle250ai wants to merge 3 commits into
dustin:masterfrom
walle250ai:feature/rename-to-format-float-comma

Conversation

@walle250ai

Copy link
Copy Markdown

Summary

Follow-up to #147. Renames CommafWithPrecisionFormatFloatComma and adds explicit documentation distinguishing it from CommafWithDigits.

Changes

Naming rationale:

Function File Rounding Separators
FormatFloat number.go stdlib
Commaf / CommafWithDigits commaf.go truncation
FormatFloatComma comma.go strconv.FormatFloat (half-to-even)

Godoc addition:

Key differences from CommafWithDigits:
  - FormatFloatComma uses strconv.FormatFloat, which rounds the decimal
    part to the specified number of digits (half-to-even rounding)
  - CommafWithDigits simply truncates the decimal part without rounding

New test case illustrating the difference:

FormatFloatComma(1234.5678, 2)  // "1,234.57"  — rounded
CommafWithDigits(1234.5678, 2)  // "1,234.56"  — truncated

All existing tests continue to pass.

🤖 Generated with Claude Code

walle250ai and others added 3 commits April 28, 2026 21:32
Adds CommafWithPrecision(num float64, digits int) string that formats
a float with thousands-separator commas and a fixed decimal precision.
FormatFloat already exists in number.go with a different signature so
a new name is used. Delegates to strconv.FormatFloat for rounding,
then applies the same comma-insertion logic as Commaf/CommafWithDigits.
Tests cover positive, negative, zero, digits=0/2/4.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…CommafWithDigits

Establishes a clear naming axis: FormatFloat (no separators, format-string)
vs FormatFloatComma (thousands separators, fixed precision). Adds godoc note
that FormatFloatComma rounds via strconv.FormatFloat while CommafWithDigits
truncates. Test added to make the rounding/truncation contrast explicit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant