dimanche 19 juin 2016

Socialchef query css


Hi I have seen that stack overflow wrote the code for socialchef to covert their decimal input into fraction.

How can I write or add a code to input fraction and manta in as a fraction...
I really need assistance.

This is the code in the theme utils...

// code thanks to Bryan [http://stackoverflow.com/a/26684935][1]
public static function convert_decimal_to_fraction($decimal){

    $big_fraction = SocialChef_Theme_Utils::float_to_rat($decimal, 0.1);
    if ($big_fraction) {
        $num_array = explode('/', $big_fraction);
        if (count($num_array) > 1) {
            $numerator = $num_array[0];
            $denominator = $num_array[1];
            if ($denominator) {
                $whole_number = floor( $numerator / $denominator );
                $numerator = $numerator % $denominator;

                if($numerator == 0){
                    return $whole_number;
                }else if ($whole_number == 0){
                    return $numerator . '/' . $denominator;
                }else{
                    return $whole_number . ' ' . $numerator . '/' . $denominator;
                }
            }
        }
    }
    return 0;

(reviewer addition) : StackOverflow reference : http://stackoverflow.com/a/26684935


Aucun commentaire:

Enregistrer un commentaire