Skip to the content
Documentation

Float Field Type: comparison of v.2 vs v.4

No ratings yet

Versions Compared

Old Version 2

changes.mady.by.user Dominika Kurek

Saved on Apr 29, 2016

compared with

New Version Current

changes.mady.by.user André Rømcke

Saved on Jan 04, 2017

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This Field Type represents a float value.

Name Internal name Expected input
Float ezfloat float

Description

This Field Type stores numeric values which will be provided as floats.

PHP API Field Type 

Input expectations

The Field Type expects a number as input. Both decimal and integer numbers are accepted.

Type Example
float 194079.572
int 144

Value object

Properties

The Value class of this field type contains the following properties:

Property Type Description
$value float This property will be used to store the value provided as a float.
Code Block
language php
title Value object content example
linenumbers true
use eZ\Publish\Core\FieldType\Float\Type;

// Instantiates a Float Value object
$floatValue = new Type\Value();

$float->value = 284.773
Constructor

The Float\Value constructor will initialize a new Value object with the value provided. It expects a numeric value with or without decimals.

Code Block
language php
title Constructor example
linenumbers true
use eZ\Publish\Core\FieldType\Float\Type;

// Instantiates a Float Value object
$floatValue = new Type\Value( 284.773 );

Validation

This Field Type supports FloatValueValidator, defining maximal and minimal float value:

Name Type Default value Description
minFloatValue float falsenull This setting defines the minimum value this FieldType will allow as input.
maxFloatValue float falsenull This setting defines the maximum value this FieldType will allow as input.
Code Block
language php
title Validator configuration example in PHP
linenumbers true
use eZ\Publish\Core\FieldType\Float\Type;

$contentTypeService = $repository->getContentTypeService();
$floatFieldCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct( "float", "ezfloat" );

// Accept only numbers between 0.1 and 203.99
$floatFieldCreateStruct->validatorConfiguration = array(
    "FileSizeValidator" => array(
		"minFloatValue" => 0.1,
		"maxFloatValue" => 203.99
    )
);

Settings

This Field Type does not support settings.

 

 

Comments

Add a comment

Comments are read by a moderator before they appear.