Php中的值格式删除caracteres

I have this value :

"24,7 km"

i would like to remove "Km" and get only 24,7 as a float number ! someone know how i could do this ? thanks a lot in advance

here my code actualy :

Route::get('/test', function () {

    $origin = '155 avenue franklin roosevelt 11000 Carcassonne';

    $destination = '36 avenue André Chenier 11300 Limoux';

    $response = \GoogleMaps::load('directions')
        ->setParam([
            'origin'          => $origin,
            'destination'     => $destination,
            'mode' => 'driving' ,
            'language' => 'fr',

        ])->get();



   $parsed_json = (json_decode($response));


   $distance = $parsed_json->{'routes'}[0]->{'legs'}[0]->{'distance'}->{'text'};

   dd($distance);

UPDATE WORKING :

  $parsed_json = (json_decode($response));


        $distance = $parsed_json->{'routes'}[0]->{'legs'}[0]->{'distance'}->{'text'};


        $a = $distance;
        $b = str_replace(" km",'',$a);
        $c = str_replace(",",'.',$b);

        dd($c);
$a = "24,7 km";
$b = str_replace(" km",'',$a);
$c = str_replace(",",'.',$b);