Changeset 32 for trunk/PrefixMultiplier.php
- Timestamp:
- Apr 7, 2020, 1:06:13 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/PrefixMultiplier.php
r5 r32 74 74 function TruncateDigits($Value, $Digits = 4) 75 75 { 76 for ($II = 2; $II > -6; $II--)76 for ($II = 2; $II > -6; $II--) 77 77 { 78 if ($Value >= pow(10, $II))78 if ($Value >= pow(10, $II)) 79 79 { 80 if ($Digits < ($II + 1)) $RealDigits = $II + 1;80 if ($Digits < ($II + 1)) $RealDigits = $II + 1; 81 81 else $RealDigits = $Digits; 82 82 $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1); … … 84 84 } 85 85 } 86 return ($Value);86 return $Value; 87 87 } 88 88 … … 93 93 $Negative = ($Value < 0); 94 94 $Value = abs($Value); 95 if (($Unit == '') and ($PrefixType != 'Time'))96 return ($this->TruncateDigits($Value, $Digits));95 if (($Unit == '') and ($PrefixType != 'Time')) 96 return $this->TruncateDigits($Value, $Digits); 97 97 98 98 $I = $PrefixMultipliers[$PrefixType]['BaseIndex']; 99 if ($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);99 if ($Value == 0) return $Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit; 100 100 101 if ($Value > 1)101 if ($Value > 1) 102 102 { 103 while ((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1))103 while ((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1)) 104 104 $I = $I + 1; 105 105 } else 106 if ($Value < 1)106 if ($Value < 1) 107 107 { 108 while ((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1))108 while ((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1)) 109 109 $I = $I - 1; 110 110 } … … 113 113 // Truncate digits count 114 114 $Value = $this->TruncateDigits($Value, $Digits); 115 if ($Negative) $Value = -$Value;116 return ($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);115 if ($Negative) $Value = -$Value; 116 return $Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit; 117 117 } 118 118 }
Note:
See TracChangeset
for help on using the changeset viewer.