-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weight.php
70 lines (60 loc) · 872 Bytes
/
Weight.php
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
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
namespace UnitConvert;
class Weight
{
private float $kg;
/**
* From kilograms (kg)
*/
public static function from_kg(float $kg): self
{
return new static ($kg);
}
/**
* From grams (g)
*/
public static function from_g(float $g): self
{
return new static ($g / 1000);
}
public function __construct(float $kg)
{
$this->kg = $kg;
}
/**
* To kilograms (kg)
*/
public function to_kg(): float
{
return $this->kg;
}
/**
* To grams (g)
*/
public function to_g(): float
{
return $this->kg / 1000;
}
/**
* To pounds (lb)
*/
public function to_lb(): float
{
return $this->kg * 2.204623;
}
/**
* To stones (st)
*/
public function to_st(): float
{
return $this->kg * 0.157473;
}
/**
* To ounces (oz)
*/
public function to_oz(): float
{
return $this->kg * 35.27396;
}
}