Have you seen our new video tutorials? Check it out!

Decimal Field Type

The decimal field type provides a precision decimal input.

Introduction

anomaly.field_type.decimal

The decimal field type provides a customizable precision decimal number input.

Configuration

Below is the full configuration available with defaults values:

"example" => [
    "type"   => "anomaly.field_type.decimal",
    "config" => [
        "default_value" => null,
        "separator" => ",",
        "point"     => ".",
        "decimals"  => 2,
        "min"       => null,
        "max"       => null,
    ]
]
Configuration
Key Example Description

default_value

25.5

The default value.

separator

The thousands separator.

point

,

The decimal point.

decimals

4

The decimal precision to enforce.

min

0.01

The minumum value allowed.

max

99.99

The maximum value allowed.

Usage

This section will show you how to use the field type via API and in the view layer.

Setting Values

You can set the decimal field type value with any integer or float.

$entry->example = 25.15;

$entry->example = 25.151415;

$entry->example = 25;
Note: The set value will be formatted to fit the field type's configured precision automatically.

Basic Output

The decimal field type returns null or the formatted decimal.

$entry->example; // 25.15

Presenter Output

This section will show you how to use the decorated value provided by the \Anomaly\DecimalFieldType\DecimalFieldTypePresenter class.

DecimalFieldTypePresenter::format()

The format method returns the formatted number string according to configuration.

Returns: string
Example
$decorated->example->format();
Twig
{{ decorated.example.format() }}

DecimalFieldTypePresenter::currency()

The currency method returns the currency formatted value.

Returns: string
Arguments
Key Required Type Default Description

$currency

false

string

The currency field value or default configured currency.

The currency to format for.

$field

false

string

currency

The slug of the currency field.

Example
$decorated->example->currency();
Twig
{{ decorated.example.currency() }}