Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

Float precision issue


3 Posts   842 Views


1 November 2011 at 6:37pm (Last edited: 1 November 2011 6:38pm), Community Member, 159 Posts


I have a feeling that there is a bit of an issue regarding Float DBField types and the precision.

If I create a Float static, and setup a NumericField through which I enter values in the CMS, despite whatever depth of precision of value I enter, it always defaults to 3 decimal places.

As I set breakpoints through the code and step through, it appears that the correct value is being set initially (ie correct number of decimal places) but there is a problem (possibly with the underlying DB query) whereby only a 3 decimal place precision floating point value is read for display in the NumericField.

I can confirm this when I do an SQL query (or look at table via phpMyAdmin) on that field directly - it returns the value to 3 decimal places.

The reason I think this is a problem is that, even though the original setting of the value works, on successive reads and updates (even if the value in the NumericField in the CMS isn't altered) the value read value from the DB has less precision than the originally stored value and will be overwritten on the next "Save".

Any ideas on how to fix this or how to set the precision on Floats read into NumericFields? Would you agree that this is a bug?

eg. [url=]from Geocodable.php[/url]

   public function extraStatics() {
      return array('db' => array(
         'Lat' => 'Float',
         'Lng' => 'Float'

eg. CustomSiteConfig.php

public function updateCMSFields(FieldSet $fields) {
$fields->addFieldToTab("Root.Geo", new NumericField("Lat", "Latitude"));
$fields->addFieldToTab("Root.Geo", new NumericField("Lng", "Longitude"));

Thanks very much.



1 November 2011 at 10:27pm Forum Moderator, 1796 Posts


I didn't read through your whole post (sorry) - I just have the advice to use a decimal type instead to control the precisison...

      'Price'             => 'Decimal(6,2)',



3 November 2011 at 3:28pm Community Member, 159 Posts

Hi Barry,

Thanks for your reply. Works well. Using Decimal(X,Y) caused an issue in dev/build, for which I [url=]posted[/url] on the forum. It's working well now.

Thanks again for your good advice.