Normalise fractions.

Parameters

string:

Return value

string

1 call to ExifPHPExtension::_normalise_fraction()
ExifPHPExtension::_reformat in ./ExifPHPExtension.php
Helper function to reformat fields where required.

File

./ExifPHPExtension.php, line 222

Class

ExifPHPExtension
This is a helper class to handle the whole data processing of exif.

Namespace

Drupal\exif

Code

public function _normalise_fraction($fraction) {
    $parts = explode('/', $fraction);
    $top = $parts[0];
    $bottom = $parts[1];
    if ($top > $bottom) {
        // Value > 1.
        if ($top % $bottom == 0) {
            $value = $top / $bottom;
        }
        else {
            $value = round($top / $bottom, 2);
        }
    }
    else {
        if ($top == $bottom) {
            // Value = 1.
            $value = '1';
        }
        else {
            // Value < 1.
            if ($top == 1) {
                $value = '1/' . $bottom;
            }
            else {
                if ($top != 0) {
                    $value = '1/' . round($bottom / $top, 0);
                }
                else {
                    $value = '0';
                }
            }
        }
    }
    return $value;
}