Skip to content

Commit a35854c

Browse files
committed
Add 32bit support.
1 parent 7230d98 commit a35854c

5 files changed

+44
-12
lines changed

.travis.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ go:
33
- 1.4.2
44
- 1.5
55
- tip
6+
env:
7+
global:
8+
- BUILD_GOARCH=amd64
9+
matrix:
10+
- BUILD_GOOS=linux
11+
- BUILD_GOOS=darwin
12+
- BUILD_GOOS=windows
613
before_install:
714
- go get github.com/axw/gocov/gocov
815
- go get github.com/mattn/goveralls
916
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
1017
script:
11-
- $HOME/gopath/bin/goveralls -service=travis-ci
18+
- $HOME/gopath/bin/goveralls -service=travis-ci

formatnumber.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package accounting
33
import (
44
"bytes"
55
"fmt"
6-
"math"
76
"math/big"
87
"reflect"
98
"strings"
@@ -87,11 +86,11 @@ func FormatNumberInt(x int, precision int, thousand string, decimal string) stri
8786
var result string
8887
var minus bool
8988

90-
if x == math.MinInt64 {
91-
return FormatNumber(x, precision, thousand, decimal)
92-
}
93-
9489
if x < 0 {
90+
if x*-1 < 0 {
91+
return FormatNumber(x, precision, thousand, decimal)
92+
}
93+
9594
minus = true
9695
x *= -1
9796
}

formatnumber_32bit_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// +build 386
2+
3+
package accounting
4+
5+
import (
6+
"math"
7+
"testing"
8+
)
9+
10+
func TestFormatNumber32Bit(t *testing.T) {
11+
AssertEqual(t, FormatNumber(math.MaxInt32, 10, ",", "."), "2,147,483,647.0000000000")
12+
AssertEqual(t, FormatNumber(math.MinInt32, 10, ",", "."), "-2,147,483,648.0000000000")
13+
}

formatnumber_64bit_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// +build amd64
2+
3+
package accounting
4+
5+
import (
6+
"math"
7+
"testing"
8+
)
9+
10+
func TestFormatNumber64Bit(t *testing.T) {
11+
AssertEqual(t, FormatNumber(math.MaxInt64, 10, ",", "."), "9,223,372,036,854,775,807.0000000000")
12+
AssertEqual(t, FormatNumber(math.MinInt64, 10, ",", "."), "-9,223,372,036,854,775,808.0000000000")
13+
}
14+
15+
func TestFormatNumberInt64Bit(t *testing.T) {
16+
AssertEqual(t, FormatNumberInt(math.MaxInt64, 10, ",", "."), "9,223,372,036,854,775,807.0000000000")
17+
AssertEqual(t, FormatNumberInt(math.MinInt64+1, 10, ",", "."), "-9,223,372,036,854,775,807.0000000000")
18+
AssertEqual(t, FormatNumberInt(math.MinInt64, 10, ",", "."), "-9,223,372,036,854,775,808.0000000000")
19+
}

formatnumber_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package accounting
22

33
import (
4-
"math"
54
"math/big"
65
"testing"
76
)
@@ -14,8 +13,6 @@ func TestFormatNumber(t *testing.T) {
1413
AssertEqual(t, FormatNumber(-123.123123, 5, ",", "."), "-123.12312")
1514
AssertEqual(t, FormatNumber(-12.123123, 5, ",", "."), "-12.12312")
1615
AssertEqual(t, FormatNumber(-1.123123, 5, ",", "."), "-1.12312")
17-
AssertEqual(t, FormatNumber(math.MaxInt64, 10, ",", "."), "9,223,372,036,854,775,807.0000000000")
18-
AssertEqual(t, FormatNumber(math.MinInt64, 10, ",", "."), "-9,223,372,036,854,775,808.0000000000")
1916
AssertEqual(t, FormatNumber(-1, 3, ",", "."), "-1.000")
2017
AssertEqual(t, FormatNumber(-10, 3, ",", "."), "-10.000")
2118
AssertEqual(t, FormatNumber(-100, 3, ",", "."), "-100.000")
@@ -54,9 +51,6 @@ func TestFormatNumber(t *testing.T) {
5451
}
5552

5653
func TestFormatNumberInt(t *testing.T) {
57-
AssertEqual(t, FormatNumberInt(math.MaxInt64, 10, ",", "."), "9,223,372,036,854,775,807.0000000000")
58-
AssertEqual(t, FormatNumberInt(math.MinInt64+1, 10, ",", "."), "-9,223,372,036,854,775,807.0000000000")
59-
AssertEqual(t, FormatNumberInt(math.MinInt64, 10, ",", "."), "-9,223,372,036,854,775,808.0000000000")
6054
AssertEqual(t, FormatNumberInt(-1, 3, ",", "."), "-1.000")
6155
AssertEqual(t, FormatNumberInt(-10, 3, ",", "."), "-10.000")
6256
AssertEqual(t, FormatNumberInt(-100, 3, ",", "."), "-100.000")

0 commit comments

Comments
 (0)