Greetings,

I have a CCK integer field that must be a minimum of 6 characters. Some figures that will go into this field are less than 6 characters, so we are putting zeros in front as needed to make the number 6 characters.

For example, the number 329 becomes 000329.

The problem I'm running into is that because it is type integer, the leading zeros are being trimmed by default and therefore the number shows as 329 rather than 0003329.

Does anyone have any insight into how to remedy this so that the leading zeros are not trimmed?

Thanks in advance.

Scott

Comments

Rix-1’s picture

+1

cholden’s picture

I'm desperate to find a solution to this issue as well. I could use a normal text field to get the zeros right, but I need the way the integer sorts in views.

karens’s picture

Status: Active » Fixed

An integer field is stored as an integer, you can't make it into something different. If you want leading zeros it is not an integer, it is probably a text field. If you have stored it with leading zeros, it should sort correctly as a text field.

cholden’s picture

I solved it with the text field as you suggested. But it didn't sort as the integer field did. I solved the sorting problem by adding a Computed Field which converts the value of the text field as an integer. I used this as the sort field in views. Works perfect.

Here's my computed code for the Computed CCK field:
$node_field[0]['value'] = (int)($node->field_productstyle[0]['value']);

…and the Display Format:
$display = $node_field_item['value'];

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.