From 79c0fceafef020cbc8bb2553c15611cd500190f2 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 15:32:39 +0000 Subject: [PATCH] Fix formatting for negative numbers --- postgres/numeric/numeric.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/postgres/numeric/numeric.go b/postgres/numeric/numeric.go index 73fdb16..8d0cc5e 100644 --- a/postgres/numeric/numeric.go +++ b/postgres/numeric/numeric.go @@ -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++ }