currency.php
1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
class Flora_Model_Shop_Currency extends Flora_Model
{
public $name;
public $usdvalue;
public $format;
public $title;
public $description;
public $rounding;
public $rounding_direction;
public $floor_to;
public function convert($usdvalue)
{
return $this->formatvalue($this->convert2int($usdvalue));
}
public function formatvalue($value)
{
return sprintf($this->format, $value);
}
public function convert2int($usdvalue)
{
return $this->round($this->usdvalue * $usdvalue, 2);
}
public function round($value, $decimals = 0)
{
if (!$this->rounding) {
return round($value, $decimals);
} else {
$value = $this->rounding * ceil($value / $this->rounding);
if ($this->rounding_direction == 'asc') {
$value = $this->rounding * floor($value / $this->rounding);
}
return $value;
}
}
public function floor($value){
if ($this->floor_to == 0){
return floor($value);
}
if($this->floor_to < 0){
$this->floor_to *= -1;
}
return floor($value / pow(10, $this->floor_to)) * pow(10, $this->floor_to);
}
public function format($value, $decimals=0)
{
return sprintf($this->format, round($value, $decimals));
}
public function onlyFloored($price, $realprice, $count){
$i = $this->floor_to < 0 ? $this->floor_to * -1 : $this->floor_to;
return ($realprice - $price)/$count <= pow(10, $i);
}
}