I've implemented the CCK Money module in my site and works really good. The problem comes when I have to submit a large numbers, let's say U$S 50,000,000. I know that not everyone needs a huge field in their databases, but it would be good to make this optional.

Comments

wim leers’s picture

Category: feature » bug

From money_field_settings() (the implementation of the hook_field_settings() CCK hook):

    case 'database columns':
      $columns['amount'] = array(
        'type' => 'int',
        'length' => 13,
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => FALSE,
      );
      $columns['currency'] = array('type' => 'varchar', 'length' => 3);
      return $columns;

As you can see, I've set the amount to be integers of length 13. The last two of those are used for decimals, which leaves you with 11 symbols left, enough for almost 100 billion. Seems enough to me.

However, when I try the amount you suggested (fifty million), it is processed to somehow be -1. I'll have to figure out why that happens.

A patch is welcome, of course :)

soflete’s picture

Sorry, I thought there was a lower limit. I also believe that a hundred billion is enough. I'll try to find the problem myself, and if I succed I'll let you know. Thanks.

wim leers’s picture

Excellent! Looking forward to get to know about the cause of this. I tested this:

echo 50000000/100;

And that worked just fine. So it's not that PHP can't handle numbers that big (which would be silly too).

soflete’s picture

It definetly has something to do with using an int for storing the value. The maximum value you can submit is 2147483648, wich is the maximum value for integer as I read in the pages of mysql: http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html. I have never made a CCK field module, but I'll check how this can be changes to bigint or similar. What do you think? Greetings.

wim leers’s picture

That's it!

2147483648
versus
5000000000 (50 million * 100 cents)

That's almost twice as big as the allowed size. Sigh. I set it to bigint, keeping the same length (13), and voila, it worked. At least, I could get it working in MySQL. Now it won't work in PHP, or Drupal, or CCK. SIGH! I hope you can continue your search now.

soflete’s picture

That's true, I changed it to bigint in the CCK definition. When I check the field in the database it's actually a bigint, anyway there is something in the middle that still keeps converting the value into an int. Could it be a CCK module issue? I'll keep looking.

soflete’s picture

Look at what I found: http://drupal.org/node/76432 Looks like there's a problem with CCK number conversion. So perhaps the solution is out of the scope of this module. What do you think?

wim leers’s picture

You're probably right. I'll have to look at it more in-depth though, to confirm that that's the cause. If you'd like to help narrow down the cause, start looking in the code that handles the DB interaction.

wim leers’s picture

Title: Bigger numbers » Use bigint instead of int
Assigned: Unassigned » wim leers
Category: bug » task
Status: Active » Fixed

I've now configured the database definition to use bigint. If you encounter any problems, please open a new issue.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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