gpt4 book ai didi

php - 在laravel中将数字四舍五入到最接近的9

转载 作者:行者123 更新时间:2023-12-03 16:19:46 24 4
gpt4 key购买 nike

我想把一个数字四舍五入到最接近的 9,这是一个例子
(12,24,37,75,80)
如果我给了这个输入想要得到如下给出的输出
(19,29,39,79,89)
我正在使用 PHP(laravel),请帮助我。

最佳答案

$input = [12,24,37,75,80];

$output = array_map(function($num) {
return (int)($num / 10) * 10 + 9;
}, $input);

关于php - 在laravel中将数字四舍五入到最接近的9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65392179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com