php - APi解析小数点后2位?
问题描述
我有一个代码可以通过 API 更新 Steam 服务游戏中的项目列表。作为回应,这些价格在我看来是这样的"price":0.64000000000000001,"count":897,"bprice":0.080000000000000002
:如何在 API 解析阶段使值price
和bprice
小数点后有 2 位数字?
我的解析代码:
public static function updatePrices()
{
if ($data = json_decode(file_get_contents(self::STEAMP)) ?? false) {
if ($data->success) {
$items_in_res = new \stdClass();
foreach($data->items as $key => $item) {
if ($item->count > 50 ) {
if ($item->bcount > 20) {
if ($item->price <= 1) {
$item->price = 0.64;
}
$items_in_res->$key = $item;
}
}
}
Storage::disk('local')->put(self::Prices, json_encode([
'time' => time(),
'items' => $items_in_res
]));
return $items_in_res;
} else {
\Log::error('Error: ' . $data->message);
return false;
}
} else {
\Log::error('Error updating prices!');
return false;
}
}
解决方案
推荐阅读
- javascript - 如何在控制台中控制台记录一个大的彩色文本
- c++ - 将 lambdas 作为模板参数传递:实际推导出的类型是什么?
- javascript - 未定义 Jest 测试中的 FileReader、File 和 TextDecoder
- python - Kivy Accordion:空间不足警告
- javascript - Google reCaptcha v3 将成功返回为 false
- javascript - 即使使用 setTimeout 也无法在同一块中重新打开子窗口
- python - 如何使用 pandas_profiling 对表进行数据分析
- java - 在多个包中创建可访问的编写器
- c# - 调用某个 url 时尝试重定向
- c# - 垃圾收集器在执行低级 C++ 代码时过早(可能)启动