07-18-2023, 08:27 PM
You can take advantage of the `NilClass` provided `#to_i` method, which will return zero for `nil` values:
unless discount.to_i.zero?
# Code here
end
If `discount` can be fractional numbers, you can use `#to_f` instead, to prevent the number from being rounded to zero.
unless discount.to_i.zero?
# Code here
end
If `discount` can be fractional numbers, you can use `#to_f` instead, to prevent the number from being rounded to zero.