You are here

protected static function DecimalItem::getDecimalDigits in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php \Drupal\Core\Field\Plugin\Field\FieldType\DecimalItem::getDecimalDigits()

Helper method to get the number of decimal digits out of a decimal number.

Parameters

int $decimal: The number to calculate the number of decimals digits from.

Return value

int The number of decimal digits.

1 call to DecimalItem::getDecimalDigits()
DecimalItem::generateSampleValue in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php
Generates placeholder field values.

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php, line 165

Class

DecimalItem
Defines the 'decimal' field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

protected static function getDecimalDigits($decimal) {
  $digits = 0;
  while ($decimal - round($decimal)) {
    $decimal *= 10;
    $digits++;
  }
  return $digits;
}