function NumericItemBase::truncateDecimal
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php \Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase::truncateDecimal()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php \Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase::truncateDecimal()
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php \Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase::truncateDecimal()
Helper method to truncate a decimal number to a given number of decimals.
Parameters
float $decimal: Decimal number to truncate.
int $num: Number of digits the output will have.
Return value
float Decimal number truncated.
2 calls to NumericItemBase::truncateDecimal()
- DecimalItem::generateSampleValue in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ DecimalItem.php - Generates placeholder field values.
- FloatItem::generateSampleValue in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ FloatItem.php - Generates placeholder field values.
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ NumericItemBase.php, line 124
Class
- NumericItemBase
- Base class for numeric configurable field types.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
protected static function truncateDecimal($decimal, $num) {
return floor($decimal * pow(10, $num)) / pow(10, $num);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.