Fix formatting for negative numbers
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Jan Bader 2022-02-25 15:32:39 +00:00
parent 1ea3590fd6
commit 79c0fceafe

View File

@ -129,7 +129,11 @@ func (n Numeric) String() string {
exp = -exp
for length <= exp {
bytes = append([]byte{byte('0')}, bytes...)
if n.Int.Int64() < 0 {
bytes = append([]byte{bytes[0], byte('0')}, bytes[1:]...)
} else {
bytes = append([]byte{byte('0')}, bytes...)
}
length++
}
@ -166,7 +170,11 @@ func (n Numeric) MarshalJSON() ([]byte, error) {
exp = -exp
for length <= exp {
bytes = append([]byte{byte('0')}, bytes...)
if n.Int.Int64() < 0 {
bytes = append([]byte{bytes[0], byte('0')}, bytes[1:]...)
} else {
bytes = append([]byte{byte('0')}, bytes...)
}
length++
}