【问题标题】:Sonata Admin - convert seconds to millisecondsSonata Admin - 将秒转换为毫秒
【发布时间】:2019-05-27 07:45:51
【问题描述】:

我正在生成我的视图,其中包含要在奏鸣曲管理面板中显示的字段。我的数据库中有一个浮点字段,它表示需要以毫秒为单位转换的秒数(乘以 1000 并四舍五入为 0 位小数)以供显示。

谁能帮帮忙。

代码:

  protected function configureShowFields(ShowMapper $showMapper)
{

    $ms = $getMs->getResponseTime(); --- this works
    $milliseconds = round($ms / 1000, 2);


    $showMapper
        ->tab('Info')
        ->add('id')
        ->add('fieldOne')
        ->add('fildTwo')
        ->add('seconds', 'decimal', array(
            'pattern' => $milliseconds
        ))
        ->end()
        ->end()
}

【问题讨论】:

    标签: php symfony sonata-admin symfony-sonata milliseconds


    【解决方案1】:

    要将数字向上舍入到最接近的整数,请查看the ceil function。 要将数字向下舍入到最接近的整数,请查看 the floor function

    /* Seconds */
    $s = $getMs->getResponseTime();
    
    /* Milliseconds */
    $ms = $s*1000;
    
    /* Rounded milliseconds */
    $milliseconds = floor($ms);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 2011-10-28
      • 2018-11-16
      • 2022-01-17
      相关资源
      最近更新 更多