From 3c1d83d8a29ca77a07e612aaf40d9f36a6444b07 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Mon, 7 Feb 2022 16:07:37 +0000 Subject: [PATCH] Fix negative values smaller than zero --- postgres/numeric.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/postgres/numeric.go b/postgres/numeric.go index b5079c2..3d477b6 100644 --- a/postgres/numeric.go +++ b/postgres/numeric.go @@ -120,6 +120,9 @@ func (n Numeric) MarshalJSON() ([]byte, error) { split := length - exp bytesWithSeparator = append(bytesWithSeparator, bytes[:split]...) + if split == 1 && n.Int.Int64() < 0 { + bytesWithSeparator = append(bytesWithSeparator, byte('0')) + } bytesWithSeparator = append(bytesWithSeparator, byte('.')) bytesWithSeparator = append(bytesWithSeparator, bytes[split:]...) return bytesWithSeparator, nil