1 <?php
2
3 /* --------------------------------------------------------------
4 DecimalType.inc.php 2015-11-04 gm
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 /**
14 * Class DecimalType
15 *
16 * Shared decimal type class. Use the "asDecimal" method for getting the plain value.
17 *
18 * @category System
19 * @package Shared
20 * @subpackage Types
21 */
22 class DecimalType
23 {
24 /**
25 * Instance Value
26 *
27 * @var float
28 */
29 protected $value;
30
31
32 /**
33 * Class Constructor
34 *
35 * @throws InvalidArgumentException
36 *
37 * @param float $p_value
38 */
39 public function __construct($p_value)
40 {
41 if(!is_numeric($p_value) || (float)$p_value != $p_value)
42 {
43 throw new InvalidArgumentException('DecimalType: Invalid argument value given (expected float numeric got '
44 . gettype($p_value) . '): ' . $p_value);
45 }
46
47 $this->value = (float)$p_value;
48 }
49
50
51 /**
52 * Get the instance value as decimal.
53 *
54 * @return float
55 */
56 public function asDecimal()
57 {
58 return $this->value;
59 }
60 }