Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: go

go:
- master

script:
- go test -v ./...
9 changes: 5 additions & 4 deletions cash.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ func (z *Cash) String() string {
if z.IsPositive() != true {
neg=true
z.Amt = z.Amt * -1 // make positive
buf.WriteString("(")
}

buf.WriteRune(z.Currency) // dollar sign
// decimal
decRaw := strconv.FormatInt(z.Amt, 10)
decRawLen := utf8.RuneCountInString(decRaw)
Expand Down Expand Up @@ -232,8 +230,11 @@ func (z *Cash) String() string {
buf.WriteString(")")
z.Amt = z.Amt * -1 // make negative
}

return buf.String()
if neg {
return "(" + string(z.Currency) + strings.Trim(buf.String(), ",")
} else {
return string(z.Currency) + strings.Trim(buf.String(), ",")
}
}

// commafy string of digits; digit grouping by thousands
Expand Down
15 changes: 15 additions & 0 deletions cash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ func TestRounding(t *testing.T) {
assert.EqualValues(t, 66700, a.Amt, "should equal")
}

func TestCommas(t *testing.T) {
a, err := NewUSD().SetString("1.00")
assert.Nil(t, err)
assert.EqualValues(t, "$1.00", a.String(), "should equal")
a, err = NewUSD().SetString("1000.00")
assert.Nil(t, err)
assert.EqualValues(t, "$1,000.00", a.String(), "should equal")
a, err = NewUSD().SetString("12345.67")
assert.Nil(t, err)
assert.EqualValues(t, "$12,345.67", a.String(), "should equal")
a, err = NewUSD().SetString("-1000.00")
assert.Nil(t, err)
assert.EqualValues(t, "($1,000.00)", a.String(), "should equal")
}

func TestMulByScalar(t *testing.T) {
a := NewUSD().SetCents(9022)
var scalar int64 = 6
Expand Down