Bug #12561 PRECISION ERROR ON DECIMAL AND FLOAT COLUN
Submitted: 12 Aug 2005 21:34 Modified: 13 Aug 2005 18:11
Reporter: Roberto Spadim (Basic Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.11 OS:Linux (linux)
Assigned to: CPU Architecture:Any

[12 Aug 2005 21:34] Roberto Spadim
Description:
when i insert and update after the field valor_un must be 1.0000 and mysql convert to 0.99999

How to repeat:
# MySQL-Front Dump 2.5
#
# Host: 172.16.1.254   Database: dev_comercial
# --------------------------------------------------------
# Server version 5.0.10-beta-standard

#
# Table structure for table 'sisbov_pedido'
#

CREATE TABLE IF NOT EXISTS sisbov_pedido (
  unidade_id double NOT NULL DEFAULT '' ,
  pedido_numero bigint(20) unsigned NOT NULL DEFAULT '' ,
  orcamento_numero bigint(20) unsigned NOT NULL DEFAULT '' ,
  produtor_tipo enum('f','j') NOT NULL DEFAULT 'f' ,
  produtor_id double NOT NULL DEFAULT '' ,
  propriedade double NOT NULL DEFAULT '' ,
  item_id double NOT NULL DEFAULT '' ,
  item_id_red double NOT NULL DEFAULT '' ,
  item_certificadora char(5) NOT NULL DEFAULT '' ,
  item_industria char(5) NOT NULL DEFAULT '' ,
  item_tipo char(5) NOT NULL DEFAULT '' ,
  quantidade int(10) unsigned NOT NULL DEFAULT '' ,
  valor_un decimal(5,5) NOT NULL DEFAULT '0.00000' ,
  valor_tot decimal(10,5) NOT NULL DEFAULT '0.00000' ,
  status_certificadora enum('s','p','a') NOT NULL DEFAULT 's' ,
  status_industria enum('s','p','a') NOT NULL DEFAULT 's' ,
  status_animal enum('r','nr') NOT NULL DEFAULT 'r' ,
  vendedor_tipo enum('f','j') NOT NULL DEFAULT 'f' ,
  vendedor_id double NOT NULL DEFAULT '0' ,
  digitador_tipo enum('f','j') NOT NULL DEFAULT 'f' ,
  digitador_id double NOT NULL DEFAULT '0' ,
  data_certificadora_s datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  data_certificadora_p datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  data_certificadora_a datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  data_industria_s datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  data_industria_p datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  data_industria_a datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  data_animal datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  PRIMARY KEY (unidade_id,pedido_numero),
   KEY data_digitacao (unidade_id,data_certificadora_s,pedido_numero),
   KEY vendedor (vendedor_tipo,vendedor_id,unidade_id,pedido_numero),
   KEY item (unidade_id,pedido_numero,item_id,item_id_red),
   KEY certificadora (item_certificadora),
   KEY industria (item_industria),
   KEY tipo (item_tipo)
);

#
# Dumping data for table 'sisbov_pedido'
#

INSERT INTO sisbov_pedido (unidade_id, pedido_numero, orcamento_numero, produtor_tipo, produtor_id, propriedade, item_id, item_id_red, item_certificadora, item_industria, item_tipo, quantidade, valor_un, valor_tot, status_certificadora, status_industria, status_animal, vendedor_tipo, vendedor_id, digitador_tipo, digitador_id, data_certificadora_s, data_certificadora_p, data_certificadora_a, data_industria_s, data_industria_p, data_industria_a, data_animal) VALUES("1", "1", "0", "f", "1", "1", "51", "1", "00001", "00001", "00001", "500", "1", "500.00000", "s", "s", "r", "f", "1", "f", "1", "2005-08-11 15:15:35", "0000-00-00 00:00:00", "0000-00-00 00:00:00", "0000-00-00 00:00:00", "0000-00-00 00:00:00", "0000-00-00 00:00:00", "0000-00-00 00:00:00");

UPDATE sisbov_pedido SET valor_un= 1 WHERE unidade_id=1 AND pedido_numero=1;

Suggested fix:
???
[12 Aug 2005 21:36] Roberto Spadim
with float the same error ocurred!!!!!
[13 Aug 2005 1:51] Roberto Spadim
i tried more changes and i saw that

DECIMAL(x,x), FLOAT(x,x) get error and
DECIMAL(x+1,x), FLOAT(x+1,x) don't!
[13 Aug 2005 18:11] Jorge del Conde
Hi!

The behaviour you described is correct.  This is NOT a bug.

What happens is with decimal(5,5) you have 0 place for numbers that are left of decimal point !

For more information, read the section describing the decimal type in:

http://dev.mysql.com/doc/mysql/en/numeric-type-overview.html