MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / FloatField

Class FloatField

mongoengine/fields.py:373–412  ·  view source on GitHub ↗

Floating point number field.

Source from the content-addressed store, hash-verified

371
372
373class FloatField(BaseField):
374 """Floating point number field."""
375
376 def __init__(self, min_value=None, max_value=None, **kwargs):
377 """
378 :param min_value: (optional) A min value that will be applied during validation
379 :param max_value: (optional) A max value that will be applied during validation
380 :param kwargs: Keyword arguments passed into the parent :class:`~mongoengine.BaseField`
381 """
382 self.min_value, self.max_value = min_value, max_value
383 super().__init__(**kwargs)
384
385 def to_python(self, value):
386 try:
387 value = float(value)
388 except ValueError:
389 pass
390 return value
391
392 def validate(self, value):
393 if isinstance(value, int):
394 try:
395 value = float(value)
396 except OverflowError:
397 self.error("The value is too large to be converted to float")
398
399 if not isinstance(value, float):
400 self.error("FloatField only accepts float and integer values")
401
402 if self.min_value is not None and value < self.min_value:
403 self.error("Float value is too small")
404
405 if self.max_value is not None and value > self.max_value:
406 self.error("Float value is too large")
407
408 def prepare_query_value(self, op, value):
409 if value is None:
410 return value
411
412 return super().prepare_query_value(op, float(value))
413
414
415class DecimalField(BaseField):

Callers 15

SensorDataClass · 0.90
SensorDataWithIndexClass · 0.90
HandleNoneFieldsClass · 0.90
FamilyClass · 0.85
ProductClass · 0.85
DocClass · 0.85
CatClass · 0.85
ProductDocumentClass · 0.85
DocClass · 0.85
UserClass · 0.85
PersonClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected