[英]Laravel 8, response json return float value as string
I'm using query builder to get the data我正在使用查询生成器来获取数据
DB::table('products')->get()
the results is结果是
{"data" : [
{
"id": 1,
"name": "Product A",
"price": "100000"
},
{
"id": 1,
"name": "Product B",
"price": "150000"
}
]
}
how to cast the price back to float?如何将价格投回浮动? I have used $casts = ["price" => "float"]
but it doesn't work since I'm not using eloquent我使用$casts = ["price" => "float"]
但它不起作用,因为我没有使用 eloquent
"price": "150000"
The "price" is set as string. “价格”设置为字符串。 You need to change to number.您需要更改为数字。
"price": 150000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.