How can i check a value inside a gridview cell and round it based on it's value?
如何检查gridview单元格中的值并根据它的值对其进行舍入?
例如:
I want values that end like that (19.999) to be rounded to 20.000, (49.999) to 50.000, etc..
我想要像那样(19.999)结束的值舍入到20.000,(49.999)到50.000等。
I tried with gridview rowOptions but didn't work.
我尝试使用gridview rowOptions但没有工作。
'rowOptions' => function ($model) {
if ($model->val_liq_moeda % 10 != 0) {
$model->val_liq_moeda = round($model->val_liq_moeda, -1);
}
},
Also that Val_liq_moeda is a column from another table. I'm displaying it here using a join but when i try to access it using $model->val_liq_moeda it says
另外,Val_liq_moeda是另一个表中的列。我在这里使用连接显示它但当我尝试使用$ model-> val_liq_moeda访问它时它说
Unkonw property
Unkonw财产
Should i have to declare it as a variable in model?
我是否应该将其声明为模型中的变量?
Thanks!
谢谢!
1 个解决方案
#1
0
'rowOptions' => function ($model) {
$model->val_liq_moeda = round($model->val_liq_moeda, 3, PHP_ROUND_HALF_UP);
}
https://secure.php.net/manual/en/function.round.php
https://secure.php.net/manual/en/function.round.php
#1
0
'rowOptions' => function ($model) {
$model->val_liq_moeda = round($model->val_liq_moeda, 3, PHP_ROUND_HALF_UP);
}
https://secure.php.net/manual/en/function.round.php
https://secure.php.net/manual/en/function.round.php