Skip to content

Commit

Permalink
Add 32bit support.
Browse files Browse the repository at this point in the history
  • Loading branch information
leekchan committed Dec 11, 2016
1 parent 7230d98 commit a35854c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ go:
- 1.4.2
- 1.5
- tip
env:
global:
- BUILD_GOARCH=amd64
matrix:
- BUILD_GOOS=linux
- BUILD_GOOS=darwin
- BUILD_GOOS=windows
before_install:
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
script:
- $HOME/gopath/bin/goveralls -service=travis-ci
- $HOME/gopath/bin/goveralls -service=travis-ci
9 changes: 4 additions & 5 deletions formatnumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package accounting
import (
"bytes"
"fmt"
"math"
"math/big"
"reflect"
"strings"
Expand Down Expand Up @@ -87,11 +86,11 @@ func FormatNumberInt(x int, precision int, thousand string, decimal string) stri
var result string
var minus bool

if x == math.MinInt64 {
return FormatNumber(x, precision, thousand, decimal)
}

if x < 0 {
if x*-1 < 0 {
return FormatNumber(x, precision, thousand, decimal)
}

minus = true
x *= -1
}
Expand Down
13 changes: 13 additions & 0 deletions formatnumber_32bit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build 386

package accounting

import (
"math"
"testing"
)

func TestFormatNumber32Bit(t *testing.T) {
AssertEqual(t, FormatNumber(math.MaxInt32, 10, ",", "."), "2,147,483,647.0000000000")
AssertEqual(t, FormatNumber(math.MinInt32, 10, ",", "."), "-2,147,483,648.0000000000")
}
19 changes: 19 additions & 0 deletions formatnumber_64bit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// +build amd64

package accounting

import (
"math"
"testing"
)

func TestFormatNumber64Bit(t *testing.T) {
AssertEqual(t, FormatNumber(math.MaxInt64, 10, ",", "."), "9,223,372,036,854,775,807.0000000000")
AssertEqual(t, FormatNumber(math.MinInt64, 10, ",", "."), "-9,223,372,036,854,775,808.0000000000")
}

func TestFormatNumberInt64Bit(t *testing.T) {
AssertEqual(t, FormatNumberInt(math.MaxInt64, 10, ",", "."), "9,223,372,036,854,775,807.0000000000")
AssertEqual(t, FormatNumberInt(math.MinInt64+1, 10, ",", "."), "-9,223,372,036,854,775,807.0000000000")
AssertEqual(t, FormatNumberInt(math.MinInt64, 10, ",", "."), "-9,223,372,036,854,775,808.0000000000")
}
6 changes: 0 additions & 6 deletions formatnumber_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package accounting

import (
"math"
"math/big"
"testing"
)
Expand All @@ -14,8 +13,6 @@ func TestFormatNumber(t *testing.T) {
AssertEqual(t, FormatNumber(-123.123123, 5, ",", "."), "-123.12312")
AssertEqual(t, FormatNumber(-12.123123, 5, ",", "."), "-12.12312")
AssertEqual(t, FormatNumber(-1.123123, 5, ",", "."), "-1.12312")
AssertEqual(t, FormatNumber(math.MaxInt64, 10, ",", "."), "9,223,372,036,854,775,807.0000000000")
AssertEqual(t, FormatNumber(math.MinInt64, 10, ",", "."), "-9,223,372,036,854,775,808.0000000000")
AssertEqual(t, FormatNumber(-1, 3, ",", "."), "-1.000")
AssertEqual(t, FormatNumber(-10, 3, ",", "."), "-10.000")
AssertEqual(t, FormatNumber(-100, 3, ",", "."), "-100.000")
Expand Down Expand Up @@ -54,9 +51,6 @@ func TestFormatNumber(t *testing.T) {
}

func TestFormatNumberInt(t *testing.T) {
AssertEqual(t, FormatNumberInt(math.MaxInt64, 10, ",", "."), "9,223,372,036,854,775,807.0000000000")
AssertEqual(t, FormatNumberInt(math.MinInt64+1, 10, ",", "."), "-9,223,372,036,854,775,807.0000000000")
AssertEqual(t, FormatNumberInt(math.MinInt64, 10, ",", "."), "-9,223,372,036,854,775,808.0000000000")
AssertEqual(t, FormatNumberInt(-1, 3, ",", "."), "-1.000")
AssertEqual(t, FormatNumberInt(-10, 3, ",", "."), "-10.000")
AssertEqual(t, FormatNumberInt(-100, 3, ",", "."), "-100.000")
Expand Down

0 comments on commit a35854c

Please sign in to comment.