File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 66
77class Number extends SupportNumber
88{
9+ /**
10+ * Convert the given number to a specific bit order of magnitude.
11+ */
12+ public static function bitsToMagnitude (int |float $ bits , int $ precision = 0 , string $ magnitude = 'kbit ' ): float
13+ {
14+ $ value = match ($ magnitude ) {
15+ 'kbit ' => $ bits * 1000 ,
16+ 'mbit ' => $ bits * pow (1000 , -2 ),
17+ 'gbit ' => $ bits * pow (1000 , -3 ),
18+ 'tbit ' => $ bits * pow (1000 , -4 ),
19+ 'pbit ' => $ bits * pow (1000 , -5 ),
20+ 'ebit ' => $ bits * pow (1000 , -6 ),
21+ 'zbit ' => $ bits * pow (1000 , -7 ),
22+ 'ybit ' => $ bits * pow (1000 , -8 ),
23+ default => $ bits ,
24+ };
25+
26+ return static ::format ($ value , $ precision );
27+ }
28+
929 /**
1030 * Convert the given number to its largest bit order of magnitude.
1131 *
You can’t perform that action at this time.
0 commit comments