horse: fix formatting TenThousandths in (-1, 0)
This commit is contained in:
@@ -12,11 +12,12 @@ type TenThousandths int32
|
|||||||
|
|
||||||
func (x TenThousandths) String() string {
|
func (x TenThousandths) String() string {
|
||||||
b := make([]byte, 0, 12)
|
b := make([]byte, 0, 12)
|
||||||
|
if x < 0 {
|
||||||
|
x = -x
|
||||||
|
b = append(b, '-')
|
||||||
|
}
|
||||||
b = strconv.AppendInt(b, int64(x/1e4), 10)
|
b = strconv.AppendInt(b, int64(x/1e4), 10)
|
||||||
if x%1e4 != 0 {
|
if x%1e4 != 0 {
|
||||||
if x < 0 {
|
|
||||||
x = -x
|
|
||||||
}
|
|
||||||
b = append(b, '.')
|
b = append(b, '.')
|
||||||
b = fmt.Appendf(b, "%04d", x%1e4)
|
b = fmt.Appendf(b, "%04d", x%1e4)
|
||||||
b = bytes.TrimRight(b, "0")
|
b = bytes.TrimRight(b, "0")
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ func TestTenThousandthsString(t *testing.T) {
|
|||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{0, "0"},
|
{0, "0"},
|
||||||
|
{500, "0.05"},
|
||||||
|
{-500, "-0.05"},
|
||||||
{10000, "1"},
|
{10000, "1"},
|
||||||
{-10000, "-1"},
|
{-10000, "-1"},
|
||||||
{15000, "1.5"},
|
{15000, "1.5"},
|
||||||
|
|||||||
Reference in New Issue
Block a user