From e20cd0e503e47e37db1f9bf382b3543039adc100 Mon Sep 17 00:00:00 2001 From: kempeng <39567537+kempeng@users.noreply.github.com> Date: Wed, 25 Jul 2018 23:22:11 -0400 Subject: [PATCH] Create zero.go Zero.go defines convenience functions for testing decimal values with the zero value. These functions make code using decimal easier to read in my opinion. EqualZero() could be renamed into IsZero() --- zero.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 zero.go diff --git a/zero.go b/zero.go new file mode 100644 index 0000000..132d135 --- /dev/null +++ b/zero.go @@ -0,0 +1,31 @@ +package decimal + +// EqualZero returns whether the numbers represented by d equals zero. +func (d Decimal) EqualZero() bool { + return d.Equal(Zero) +} + +// NotZero returns whether d is not zero +func (d Decimal) NotZero() bool { + return !d.EqualZero() +} + +// GreaterThanZero (GT0) returns true when d is greater than zero. +func (d Decimal) GreaterThanZero() bool { + return d.GreaterThan(Zero) +} + +// GreaterThanOrEqualZero (GTE0) returns true when d is greater than or equal to zero. +func (d Decimal) GreaterThanOrEqualZero() bool { + return d.GreaterThanOrEqual(Zero) +} + +// LessThanZero returns true when d is less than zero. +func (d Decimal) LessThanZero() bool { + return d.LessThan(Zero) +} + +// LessThanOrEqualZero returns true when d is less than or equal to zero. +func (d Decimal) LessThanOrEqualZero() bool { + return d.LessThanOrEqual(Zero) +}