this number is defined as decimal(10,2) in mysql. it is declared like this in the form

   $form['cpm'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Cost per month'),
     '#default_value' => $node->cpm,
     '#maxlength'     => 6,
     '#required'      => FALSE,
     '#size'          => 6,
     '#weight'        => 3
   );

in validate, i have

  if ($node->cpm) {
    if (!is_numeric($node->cpm)) {
      form_set_error('cpm', t('Cost per month must be a number.'));
    }
	else $node->cpm = number_format($node->cpm, 2, '.', ''); 
  }
  else {
    // Let an empty field mean "zero."
    $node->cpm = 0;
  }

in insert, i have

  db_query("INSERT INTO {table} (..., cpm,...) ".
          "VALUES (...'%d',...)", 
          ..., $node->cpm, ...);

but when I put in 8.25, i get 8.00 in the database.

Comments

inaxio’s picture

try with '%f'. I think that drupal uses sprintf to replace it.

local’s picture

thank you, that works.