Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Suppose, we have a view with a decimal field:

enter image description here

It is output like this:

5 000.000

Is it possible to remove the ending zeros, so it looked like this:

5 000

But if there are meaningful values in the field, it should output all of them. For example:

5.100 -> 5.1
5.010 -> 5.01
5.001 -> 5.001
share|improve this question
1  
Look closer at your image..."The number of digits to the right of the decimal". Does that not have an option for 0? –  Clive Aug 29 at 8:13
    
@Clive But I want it to output all 3 digits, if there are meaningful values. So, it should output: 4.001. But if the value is 4.030 it should output: "4.03". –  user4035 Aug 29 at 8:16
1  
Ah, you didn't mention that in that question. In that case I don't think so, you'd probably need to write a custom field handler for that (unless you can find a module that provides one, but it's quite a niche requirement so you might not get lucky) –  Clive Aug 29 at 8:20
    
@Clive Thx, I improved the question. I'll write a template for that view field and use php to format the value. –  user4035 Aug 29 at 8:25
1  
I did, look at the upvote ;) –  Mołot Aug 29 at 8:43

1 Answer 1

up vote 2 down vote accepted

I created a file /theme/bartik/templates/views-view-field--open-events--page--field-coefficient.tpl.php:

<?php
print (float) $row->_field_data['id']['entity']->field_coefficient[LANGUAGE_NONE][0]['value'];

And it worked.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.