如何在不返回 PHP 中的类型的情况下回显对象的结果?

How to echo the result from an object without also returning the type in PHP?

数据库结构:

internal_id | transaction_id | transaction_value | user_id

PHP代码:

public static function getBalance() {

    $userId = Session::get('user_id');

    $database = DatabaseFactory::getFactory()->getConnection();

    $sql = "SELECT SUM(transaction_value) as sum
              FROM transactions_received
             WHERE user_id = (:user_id) LIMIT 1";
    $query = $database->prepare($sql);
    $query->execute(array(':user_id' => $userId));

    $result = $query->fetch()->sum;

    $balance = !empty($result)? $result: null;

    if($balance==null) {
        $balanceZero = "0";
        return $balanceZero;
    } else {
        return $balance;
    }

}

独立$query->fetch();输出:

 object(stdClass)#7 (1) { ["sum"]=> string(10) "0.00449300" }

$query->fetch()->sum; 输出:

string(10) "0.00449300" 

问题:

我只尝试 return 0.00449300 不包括类型。任何帮助将不胜感激!

最初通过 var_dump 而不是 print_r 输出响应。