z3c.form: Float field rendered with rounded values

We have z3c.form Float fields with float values. The values rendered in the form appeat to be rounded after the 3rd digit after the comma - which is a pita because the value represent geo locations. The culprit is zope.i18n.format.NumberFormat where some scary number formatting happens place. Is there a way to register a different formatter for Float fields or specify a different precision for the formatting of float values?

-aj

I'd probably just override the widget or monkey patch unless someone knows of a better idea....

Or maybe poke around collective.geo and see what they do with their geo values?

I believe, you can override data converter from field value to display widget value. (As I remember, it was the default data converter, which calls the number format formatter).

from z3c.form.interfaces import IDataConverter
from z3c.form.interfaces import DISPLAY_MODE
from z3c.form.interfaces import IWidget
from z3c.form.converter import FloatDataConverter as FloatDataConverterBase
from zope.schema.interfaces import IFloat


class FloatDataConverter(FloatDataConverterBase):
    implements(IDataConverter)
    adapts(IFloat, IWidget)

    def toWidgetValue(self, value):
        if self.widget.mode != DISPLAY_MODE:
            return super(FloatDataConverter, self).toWidgetValue(value)
        else:
            # magic

Thanks for help. Going with a standard TextLine field forward...this is much easier as workaround than to fiddle with these insane z3c.form indirections.

-aj

Yes, you probably could also register textline widget as a display mode widget for float fields :wink: