我需要在数据库的整数值的管理面板中设置正确的数据显示作为浮点值。
我试图使用官方文档中的十进制,整数,数字,但我没有在任何这些类型中找到“除”类型的选项。
/**
* {@inheritDoc}
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper
->add('int properties which need to display in float view (like 00.00)', 'decimal', [
'division' => 100
])
;
}
以dB为整数存储的值必须在admin中显示为float:
(int from db / 100)
你可以使用PHP的内置方法number_format()
.number_format()
函数格式化一个数千的数字。句法:
number_format(number,decimals,decimalpoint,separator)
例:
<?php
echo number_format(2, 2);
?>
结果:
2.00
我经常使用sprintf来解决这类问题。
sprintf('%.2f', 100);
输出:
string(4) "100.00"
格式字符串%.2f
的意思是:在点f
之后显示一个带有两位数的浮点.2
如果您想了解更多细节,请参阅此函数的documentation。