简体   繁体   English

如何在管理面板中设置正确的数据显示

[英]How to set up the correct display of data in the admin panel

I'm need to set up the correct display of data in the admin panel of integer values from the database as floating point values. 我需要在数据库的整数值的管理面板中设置正确的数据显示作为浮点值。

I am trying to use decimal, integer, number from official documentation, but I haven't found the option of “division” type in any of these types. 我试图使用官方文档中的十进制,整数,数字,但我没有在任何这些类型中找到“除”类型的选项。

/**
 * {@inheritDoc}
 */
protected function configureListFields(ListMapper $listMapper): void
{
    $listMapper
        ->add('int properties which need to display in float view (like 00.00)', 'decimal', [
            'division' => 100
        ])
    ;
}

It is necessary that the value that is stored in dB as an integer number be displayed in the admin as a float: 以dB为整数存储的值必须在admin中显示为float:

(int from db / 100)

You can use PHP's inbuilt method number_format() .The number_format() function formats a number with grouped thousands. 您可以使用PHP的内置方法number_format()number_format()函数格式化一个数字为千位的数字。 Syntax: 句法:

number_format(number,decimals,decimalpoint,separator)

Example: 例:

<?php

echo number_format(2, 2);
?>

Result: 结果:

2.00

I usually use sprintf for this kind of problem. 我经常使用sprintf来解决这类问题。

sprintf('%.2f', 100);

output : 输出:

string(4) "100.00"

The format string %.2f means : Display a float f with two digit after the dot .2 格式字符串%.2f表示:在点.2后显示两位数的浮点数f

Here's the documentation of this function if you want more details. 如果您想了解更多详细信息,请参阅此函数的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM