在mysql数据库表中,我有双类型列,其值为10.12、15.88、10.00等。
在获得所有这些值的同时,它返回响应10.12 15.88 10
我想保留.00的值为10.00,但它只给出10。?尝试使用浮点数和双类型,它对十进制类型很好,但是值用双引号"10.00“返回,所以它被认为是字符串,我需要它作为浮点类型或双类型
发布于 2022-01-28 05:59:54
您可以使用Laravel的属性转换https://laravel.com/docs/8.x/eloquent-mutators#attribute-casting。您的模型的$casts属性提供了一种将属性转换为公共数据类型的方便方法。
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'column_name' => 'decimal:2',
];
}https://stackoverflow.com/questions/70889260
复制相似问题