-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ArtisanCloud/develop
Develop
- Loading branch information
Showing
5 changed files
with
78 additions
and
21 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
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
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,11 @@ | ||
package object | ||
|
||
const WX_CURRENCY_UNIT float64 = 100 | ||
|
||
func ConvertToCentUnit(amount float64) int { | ||
return int(amount * WX_CURRENCY_UNIT) | ||
} | ||
|
||
func ConvertToYuanUnit(amount int) float64 { | ||
return float64(amount) / WX_CURRENCY_UNIT | ||
} |
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,42 @@ | ||
package object | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func Test_ConvertToCentUnit(t *testing.T) { | ||
|
||
var money int | ||
money = ConvertToCentUnit(1.23) | ||
assert.Equal(t, 123, money) | ||
|
||
money = ConvertToCentUnit(123) | ||
assert.Equal(t, 12300, money) | ||
|
||
money = ConvertToCentUnit(1.23456) | ||
assert.Equal(t, 123, money) | ||
|
||
money = ConvertToCentUnit(0.123456) | ||
assert.Equal(t, 12, money) | ||
|
||
money = ConvertToCentUnit(0.163456) | ||
assert.Equal(t, 16, money) | ||
|
||
money = ConvertToCentUnit(0.166456) | ||
assert.Equal(t, 16, money) | ||
} | ||
|
||
func Test_ConvertToYuanUnit(t *testing.T) { | ||
|
||
var money float64 | ||
money = ConvertToYuanUnit(123) | ||
assert.Equal(t, 1.23, money) | ||
|
||
money = ConvertToYuanUnit(12500) | ||
assert.Equal(t, 125.0, money) | ||
|
||
money = ConvertToYuanUnit(163456) | ||
assert.Equal(t, 1634.56, money) | ||
|
||
} |