[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find ONE feature... #92

Merged
Virgil merged 1 commit from agent/read---spec-code-core-go-i18n-rfc-md-ful into dev 2026-04-02 02:55:06 +00:00
2 changed files with 32 additions and 0 deletions

View file

@ -56,6 +56,11 @@ func FormatDecimalN(f float64, decimals int) string {
}
multiplier := math.Pow(10, float64(decimals))
fracInt := int64(math.Round(fracPart * multiplier))
if fracInt >= int64(multiplier) {
intPart++
intStr = formatIntWithSep(intPart, nf.ThousandsSep)
fracInt = 0
}
if fracInt == 0 {
if negative {
return "-" + intStr

View file

@ -44,6 +44,8 @@ func TestFormatDecimal(t *testing.T) {
}{
{1.5, "1.5"},
{1.0, "1"},
{1.995, "2"},
{9.999, "10"},
{1234.56, "1,234.56"},
{0.1, "0.1"},
{-0.1, "-0.1"},
@ -58,6 +60,31 @@ func TestFormatDecimal(t *testing.T) {
}
}
func TestFormatDecimalN_RoundsCarry(t *testing.T) {
svc, err := New()
if err != nil {
t.Fatalf("New() failed: %v", err)
}
SetDefault(svc)
tests := []struct {
f float64
decimals int
want string
}{
{1.995, 2, "2"},
{9.999, 2, "10"},
{999.999, 2, "1,000"},
}
for _, tt := range tests {
got := FormatDecimalN(tt.f, tt.decimals)
if got != tt.want {
t.Errorf("FormatDecimalN(%v, %d) = %q, want %q", tt.f, tt.decimals, got, tt.want)
}
}
}
func TestFormatPercent(t *testing.T) {
svc, err := New()
if err != nil {