如何获得整数的小数点

I want to get the breakdown of the charges but im stock on the decimal point, it should be the output i fill.out below. please see and check my code if there is lacking. it really could help me much. Ill show the output of my code.

$charge = 1600.50;
$base = 750;
$difference = $charge - $base;
$installment = $charge / 750;
$remainder = ($charge % 750);
$counter = 1;

if (is_float($charge)) {
    if($remainder == 0) {
        $count = 0;
        for ($i=1; $i <= round($installment); $i++) {
            $count = $count + 1;
            echo $base."
";
        }
        if(is_float($charge)){
            $exploadedAmount = explode('.', $charge);
            echo "0.".$exploadedAmount[1];              
        }
    } else {
        $count = 0;
        for ($i=1; $i <= ceil($installment); $i++) { 
            $count = $count + 1;
            if($counter != ceil($installment)){
                echo $base."
";
            }else{
                echo $remainder."
";
            }
            $counter = $counter + 1;
        }
        if(is_float($charge)){
            $exploadedAmount = explode('.', $charge);
            echo "0.".$exploadedAmount[1];              
        }
    }
} else {
    if($remainder == 0){
        $count = 0;
        for ($i=1; $i <= ceil($installment); $i++) { 
            $count = $count + 1;
            echo $base."
";
        }
    } else {
        if($difference < 0){
            echo $remainder."
";
        } else {
            $count = 0;
            for ($i=1; $i <= ceil($installment); $i++) { 
                $count = $count + 1;
                if($counter != ceil($installment)){
                    echo $base."
";                        
                }else{
                    echo $remainder."
";
                }                   
                $counter = $counter + 1;
            }
        }
    }
}

This is the output of my code.

750
750
100
0.50

But the correct output would be this.

750
750
100.50

I hope there is anyone could help me to solve this problem. it took weeks but im not able to solve this.

I don't know if i faced your problem correctly, but according to your desired output the following will do the trick.

else{

    $count = 0;
    for ($i=1; $i <= ceil($installment); $i++) { 

        $count = $count + 1;

        if($counter != ceil($installment)){
            echo $base."
";
        }else{

            // echo $remainder."
"; 
            echo $remainder + $charge-floor($charge); // get fractial part of your $charge and add it to your remainder
        }
        $counter = $counter + 1;

    }

    /* unnecessary if-statement, is already checked by surrounding if-statement
    if(is_float($charge)){  
    */

    // echo 'TRUE';
    // $exploadedAmount = explode('.', $charge);
    // echo "0.".$exploadedAmount[1];              

    }
}

I really don't understand what are you trying to do but isn't it better to write the code in partly functions?

anyways by editing this part of your code I manage to output the result you want:

$charge = 1600.50;
$base = 750;
$difference = $charge - $base;
$installment = $charge / 750;
$remainder = ($charge % 750);
$counter = 1;

if (is_float($charge)) {

    // echo "TRUE";

    if($remainder == 0){

        $count = 0;

        for ($i=1; $i <= round($installment); $i++) {
            $count = $count + 1;

            echo $base."
";


        }

        if(is_float($charge)){

            $exploadedAmount = explode('.', $charge);

            echo "0.".$exploadedAmount[1];

        }
    }
    else{

        $count = 0;
        for ($i=1; $i <= ceil($installment); $i++) {

            $count = $count + 1;

            if($counter != ceil($installment)){
                echo $base."
";
            }

            $counter = $counter + 1;

        }

        if(is_float($charge)){

// if you want to concatinate the number to previuse one you must do it here
// the extra 0.5 is echo here

            $exploadedAmount = explode('.', $charge);

            echo "$remainder.".$exploadedAmount[1];

        }
    }
}
else{

    if($remainder == 0){

        $count = 0;

        for ($i=1; $i <= ceil($installment); $i++) {
            $count = $count + 1;

            echo $base."
";
        }

    }
    else{

        if($difference < 0){

            echo $remainder."
";

        }else{

            $count = 0;
            for ($i=1; $i <= ceil($installment); $i++) {

                $count = $count + 1;

                if($counter != ceil($installment)){

                    echo $base."
";

                }else{

                    echo $remainder."
";

                }

                $counter = $counter + 1;

            }
        }
    }
}

The output will be : 750 750 100.5

echo ".".$exploadedAmount[1]."0" ;

At line number 63 , if u change that number and 0 adding at the beginning and end means your can get that accurate output and also it is applicable for other phone numbers also.