我正在使用laravel,有时非常大的数字与postgres相结合。在有问题的情况下,我试图在此表中存储数据。
Schema::create('address_statistics', function (Blueprint $table) {
$table->id();
$table->string('address')->nullable()->index();
$table->bigInteger('transaction_count');
$table->bigInteger('balance');
$table->dateTime('first_transaction');
$table->dateTime('last_transaction');
});
示例(伪代码(:
$testnumber = "13159750.11391604"; //comes from an API as string
$this->addressStatistic->balance = floatval($response["result"]["amount"]) * 100000000;
$this->addressStatistic->save();
在这种情况下,我收到一个错误:
PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "1.3159750113916E+15"
有什么办法可以绕过它吗?
在插入数据库之前,我使用 inval(( 显式解析了该数字。现在它按预期工作!