I am trying to programmatically format how an integer field displays. So far I have only been able to produce “1.00”, and I am trying to get it like so: x.xx.x. The content type is “Project” and the field is “Drupal version”.
Here is my code:
<!-- Display the drupal version with decimals --> <?php if (isset($node) && $node->type == 'project'): ?> <?php $drupal_version = field_view_field('node', $node, 'field_drupal_version', array('label'=>'default')); ?> <?php $formatted_drupal_version = number_format((float)$drupal_version, 2); ?> <?php echo "Drupal version: " . render($formatted_drupal_version); ?></span> <?php endif; ?>
output: Drupal version: 1.00
Does anyone know why this is the output, and how I can extend this function number_format to produce something in this format x.xx.x, for example “Drupal version: 7.41.1” ?
Thanks!
Sponsored by SupremePR