优化比例字符格式化

This commit is contained in:
wangxiaowei 2024-11-18 14:46:55 +08:00
parent e11ddbe18a
commit 8127f851f2

@ -15,12 +15,10 @@ class GoodsSubsidy extends Models
'list_rows'=> $get['limit'], 'list_rows'=> $get['limit'],
'page'=> $get['page'], 'page'=> $get['page'],
]); ]);
foreach ($lists as &$v) { foreach ($lists as &$v) {
$v['profit'] = self::formatStr($v['profit']); $v['profit'] = self::formatStr($v['profit']);
$v['subsidy'] = self::formatStr($v['subsidy']); $v['subsidy'] = self::formatStr($v['subsidy']);
} }
return ['count' => $lists->total(), 'lists' => $lists->getCollection()]; return ['count' => $lists->total(), 'lists' => $lists->getCollection()];
} }
@ -34,7 +32,10 @@ class GoodsSubsidy extends Models
public static function formatStr($str) public static function formatStr($str)
{ {
$s = explode('.', $str); $s = explode('.', strval($str));
return $s[1] > 0 ? $s . '%' : intval($str) . '%'; if (count($s) > 1 && $s[1] > 0) {
return $str . '%';
}
return intval($s[0]) . '%';
} }
} }