Index: trunk/phase3/languages/Language.php |
— | — | @@ -3816,28 +3816,29 @@ |
3817 | 3817 | * @return string |
3818 | 3818 | */ |
3819 | 3819 | function formatBitrate( $bps ) { |
3820 | | - $units = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' ); |
3821 | 3820 | if ( $bps <= 0 ) { |
3822 | 3821 | return str_replace( '$1', $this->formatNum( $bps ), $this->getMessageFromDB( 'bitrate-bits' ) ); |
3823 | 3822 | } |
3824 | | - $unitIndex = (int)floor( log10( $bps ) / 3 ); |
3825 | | - $mantissa = $bps / pow( 1000, $unitIndex ); |
| 3823 | + $units = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' ); |
| 3824 | + $index = 0; |
3826 | 3825 | |
3827 | 3826 | $maxIndex = count( $units ) - 1; |
| 3827 | + while ( $bps >= 1000 && $index < $maxIndex ) { |
| 3828 | + $index++; |
| 3829 | + $bps /= 1000; |
| 3830 | + } |
3828 | 3831 | |
3829 | | - if ( $unitIndex > $maxIndex ) { |
3830 | | - // Prevent code falling off end of $units array |
3831 | | - $mantissa *= ( $unitIndex - $maxIndex ) * 1000; |
3832 | | - $unitIndex = $maxIndex; |
| 3832 | + // For small units no decimal places necessary |
| 3833 | + $round = 0; |
| 3834 | + if ( $index > 1 ) { |
| 3835 | + // For MB and bigger two decimal places are smarter |
| 3836 | + $round = 2; |
3833 | 3837 | } |
3834 | | - if ( $mantissa < 10 ) { |
3835 | | - $mantissa = round( $mantissa, 1 ); |
3836 | | - } else { |
3837 | | - $mantissa = round( $mantissa ); |
3838 | | - } |
3839 | | - $msg = "bitrate-{$units[$unitIndex]}bits"; |
| 3838 | + $msg = "bitrate-{$units[$index]}bits"; |
| 3839 | + |
| 3840 | + $bps = round( $bps, $round ); |
3840 | 3841 | $text = $this->getMessageFromDB( $msg ); |
3841 | | - return str_replace( '$1', $this->formatNum( $mantissa ), $text ); |
| 3842 | + return str_replace( '$1', $this->formatNum( $bps ), $text ); |
3842 | 3843 | } |
3843 | 3844 | |
3844 | 3845 | /** |