Page 1 of 1

error with float field

Posted: Sun 23 Dec 2007 01:08
by maxchenjun
Delphi 7.0
mydac 5.20.0.12 Pro.

SQL script:

Code: Select all

CREATE TABLE IF NOT EXISTS `mydac` (
  `id` int(11) NOT NULL auto_increment,
  `price` float NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;

--
-- Daten für Tabelle `mydac`
--

INSERT INTO `mydac` (`id`, `price`) VALUES
(1, 23),
(2, 49.49),
(3, 100.01),
(4, 34.5);
All these values are shown not correctly after click on a refresh button, whose on click event is this:

Code: Select all

MyTable1.SQL.Text:= 'select * from '+MyTable1.TableName;
MyTable1.Prepare;
MyTable1.Execute;
And float values are shown as 49.4900016784668 and so on.

Is this a bug or how can I solve this problem? Thanks in advance.

Posted: Mon 24 Dec 2007 10:49
by Dimon
Described problem is a peculiarity of handling float fields by MySQL. To solve the problem, change the field type to DOUBLE or DECIMAL(11, 2).
Also, the result will be correct if you do not call the MyTable1.Prepare method.