Ignore:
Timestamp:
Apr 7, 2020, 1:06:13 AM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PrefixMultiplier.php

    r5 r32  
    7474  function TruncateDigits($Value, $Digits = 4)
    7575  {
    76     for($II = 2; $II > -6; $II--)
     76    for ($II = 2; $II > -6; $II--)
    7777    {
    78       if($Value >= pow(10, $II))
     78      if ($Value >= pow(10, $II))
    7979      {
    80         if($Digits < ($II + 1)) $RealDigits = $II + 1;
     80        if ($Digits < ($II + 1)) $RealDigits = $II + 1;
    8181          else $RealDigits = $Digits;
    8282        $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);
     
    8484      }
    8585    }
    86     return($Value);
     86    return $Value;
    8787  }
    8888
     
    9393    $Negative = ($Value < 0);
    9494    $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);
    9797
    9898    $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;
    100100
    101     if($Value > 1)
     101    if ($Value > 1)
    102102    {
    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))
    104104        $I = $I + 1;
    105105    } else
    106     if($Value < 1)
     106    if ($Value < 1)
    107107    {
    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))
    109109        $I = $I - 1;
    110110    }
     
    113113    // Truncate digits count
    114114    $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;
    117117  }
    118118}
Note: See TracChangeset for help on using the changeset viewer.