I set empty text and set 0 to be treated as empty. However, the empty text did not display for zero values. I discovered that this was because the data type was decimal and the precision was set to 2. "0.00" !== 0 is always TRUE.

Comments

darren oh’s picture

Title: Numeric fields with precision never equal zero » Zero values with decimals not being treated as zero
Assigned: darren oh » Unassigned
Status: Active » Needs review
StatusFileSize
new1018 bytes
merlinofchaos’s picture

That wont' work. The value 'foo' will show up as empty because 'foo' == 0. That's why we use !==

Instead youll have to use is_numeric I believe. If it's numeric you can test != and if it's not numeric you have to test !==

darren oh’s picture

StatusFileSize
new1.02 KB

Thanks. Updated patch attached.

darren oh’s picture

Title: Zero values with decimals not being treated as zero » Zero values with decimals not being treated as zero in views_handler_field_numeric
darren oh’s picture

Issue summary: View changes

Improved formatting and corrected error.

emman31’s picture

I have the same problem for Drupal 6. What is the best way to submit a patch? Should I create another issue?

Renee S’s picture

Issue summary: View changes

This no longer applies, but the problem still exists.

guypaddock’s picture

Status: Needs review » Needs work

The last submitted patch, 3: views-empty-decimal-values-1789294-3.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: views-empty-decimal-values-1789294-3.patch, failed testing.

crutch’s picture

Does this patch work even though failed testing? Need this solution. Thanks

joelpittet’s picture

Version: 7.x-3.5 » 7.x-3.x-dev
Status: Needs work » Needs review
StatusFileSize
new681 bytes

How about this? We just ensure we check ($value !== 0 && $value !== '0')

joelpittet’s picture

Status: Needs review » Needs work

Whoops that doesn't cover the float from the original issue just the integers.

joelpittet’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new728 bytes

Ok this should work better.

$is_zero = is_numeric($value) && !((float) $value);

Covers as 0:
0, 0.00, 0.000, '0', '0.00', '0.000'

Will ensure these don't count as 0:
'', '0.000001', 0.000001

And in the case where 'empty_zero' == TRUE, it will count '0.000' as a 0 value, and let it pass to set it to '' as I'd expect

This should really get some tests I suspect.

joelpittet’s picture

StatusFileSize
new731 bytes

While testing I still got it a bit off, it was assuming NULL was allowed not be empty the way the conditional was written.

The last submitted patch, 3: views-empty-decimal-values-1789294-3.patch, failed testing. View results

chris matthews’s picture

The 2 year old patch in #16 to views_handler_field_numeric.inc applied cleanly to the latest views 7.x-3.x-dev, but still needs review.

damienmckenna’s picture

Status: Needs review » Closed (duplicate)
Parent issue: » #1782304: Can't use "rewrite if empty" on fields using views_handler_field_numeric

This is a near complete duplicate of #1782304: Can't use "rewrite if empty" on fields using views_handler_field_numeric, only that one has test coverage too.

Could everyone here please try out the patch over there to confirm it works for you? Thanks.