forked from leekchan/accounting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
language: go | ||
go: | ||
- 1.4.2 | ||
- 1.5 | ||
- tip | ||
before_install: | ||
- go get github.com/axw/gocov/gocov | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// +build go1.5 | ||
|
||
package accounting | ||
|
||
import ( | ||
"math/big" | ||
) | ||
|
||
// FormatMoneyBigFloat only supports *big.Float value. It is faster than FormatMoney, | ||
// because it does not do any runtime type evaluation. | ||
func (accounting *Accounting) FormatMoneyBigFloat(value *big.Float) string { | ||
accounting.init() | ||
formattedNumber := FormatNumberBigFloat(value, accounting.Precision, accounting.Thousand, accounting.Decimal) | ||
return accounting.formatMoneyString(formattedNumber) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// +build go1.5 | ||
|
||
package accounting | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
) | ||
|
||
func TestFormatMoneyBigFloat(t *testing.T) { | ||
accounting := Accounting{Symbol: "$", Precision: 2} | ||
AssertEqual(t, accounting.FormatMoneyBigFloat(big.NewFloat(123456789.213123)), "$123,456,789.21") | ||
|
||
accounting = Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","} | ||
AssertEqual(t, accounting.FormatMoneyBigFloat(big.NewFloat(4999.99)), "€4.999,99") | ||
AssertEqual(t, accounting.FormatMoneyBigFloat(big.NewFloat(-4999.99)), "€-4.999,99") | ||
|
||
accounting = Accounting{Symbol: "£ ", Precision: 0} | ||
AssertEqual(t, accounting.FormatMoneyBigFloat(big.NewFloat(-500000.0)), "£ -500,000") | ||
|
||
accounting = Accounting{Symbol: "GBP", Precision: 0, | ||
Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"} | ||
AssertEqual(t, accounting.FormatMoneyBigFloat(big.NewFloat(1000000.0)), "GBP 1,000,000") | ||
AssertEqual(t, accounting.FormatMoneyBigFloat(big.NewFloat(-5000.0)), "GBP (5,000)") | ||
AssertEqual(t, accounting.FormatMoneyBigFloat(big.NewFloat(0.0)), "GBP --") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// +build go1.5 | ||
|
||
package accounting | ||
|
||
import ( | ||
"math/big" | ||
) | ||
|
||
// FormatNumberBigFloat only supports *big.Float value. | ||
// It is faster than FormatNumber, because it does not do any runtime type evaluation. | ||
func FormatNumberBigFloat(x *big.Float, precision int, thousand string, decimal string) string { | ||
return formatNumberString(x.Text('f', precision), precision, thousand, decimal) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// +build go1.5 | ||
|
||
package accounting | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
) | ||
|
||
func TestFormatNumberBigFloat(t *testing.T) { | ||
AssertEqual(t, FormatNumberBigFloat(big.NewFloat(123456789.213123), 3, ",", "."), "123,456,789.213") | ||
AssertEqual(t, FormatNumberBigFloat(big.NewFloat(-12345.123123), 5, ",", "."), "-12,345.12312") | ||
AssertEqual(t, FormatNumberBigFloat(big.NewFloat(-1234.123123), 5, ",", "."), "-1,234.12312") | ||
AssertEqual(t, FormatNumberBigFloat(big.NewFloat(-123.123123), 5, ",", "."), "-123.12312") | ||
AssertEqual(t, FormatNumberBigFloat(big.NewFloat(-12.123123), 5, ",", "."), "-12.12312") | ||
AssertEqual(t, FormatNumberBigFloat(big.NewFloat(-1.123123), 5, ",", "."), "-1.12312") | ||
} |