only trim zeros to the right of the decimal
This commit is contained in:
parent
09e8cdc109
commit
b447b6cf0a
@ -32,3 +32,20 @@ func TestBigIntSerializationRoundTrip(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFilRoundTrip(t *testing.T) {
|
||||||
|
testValues := []string{
|
||||||
|
"0", "1", "1.001", "100.10001", "101100", "5000.01", "5000",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range testValues {
|
||||||
|
fval, err := ParseFIL(v)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fval.String() != v {
|
||||||
|
t.Fatal("mismatch in values!", v, fval.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,7 +12,10 @@ type FIL BigInt
|
|||||||
|
|
||||||
func (f FIL) String() string {
|
func (f FIL) String() string {
|
||||||
r := new(big.Rat).SetFrac(f.Int, big.NewInt(build.FilecoinPrecision))
|
r := new(big.Rat).SetFrac(f.Int, big.NewInt(build.FilecoinPrecision))
|
||||||
return strings.TrimRight(r.FloatString(18), "0.")
|
if r.Sign() == 0 {
|
||||||
|
return "0"
|
||||||
|
}
|
||||||
|
return strings.TrimRight(strings.TrimRight(r.FloatString(18), "0"), ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FIL) Format(s fmt.State, ch rune) {
|
func (f FIL) Format(s fmt.State, ch rune) {
|
||||||
|
Loading…
Reference in New Issue
Block a user