ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Trunc.php
Go to the documentation of this file.
1<?php
2
4
6
7class Trunc
8{
19 public static function evaluate($value = 0, $digits = 0)
20 {
21 try {
22 $value = Helpers::validateNumericNullBool($value);
23 $digits = Helpers::validateNumericNullSubstitution($digits, null);
24 } catch (Exception $e) {
25 return $e->getMessage();
26 }
27
28 $digits = floor($digits);
29
30 // Truncate
31 $adjust = 10 ** $digits;
32
33 if (($digits > 0) && (rtrim((string) (int) ((abs($value) - abs((int) $value)) * $adjust), '0') < $adjust / 10)) {
34 return $value;
35 }
36
37 return ((int) ($value * $adjust)) / $adjust;
38 }
39}
An exception for terminatinating execution or to throw for unit testing.
static validateNumericNullBool($number)
Many functions accept null/false/true argument treated as 0/0/1.
Definition: Helpers.php:27
static validateNumericNullSubstitution($number, $substitute)
Validate numeric, but allow substitute for null.
Definition: Helpers.php:51
static evaluate($value=0, $digits=0)
TRUNC.
Definition: Trunc.php:19