I am generating my view with fields to display in sonata admin panel. I have a float field in my db that is representing seconds that needs to be converted in milliseconds (multiplied by 1000 and rounded to 0 decimals) for display.
Can anybody help out.
Code:
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()
}
To round a number UP to the nearest integer, look at the ceil function. To round a number DOWN to the nearest integer, look at the floor function.
/* Seconds */
$s = $getMs->getResponseTime();
/* Milliseconds */
$ms = $s*1000;
/* Rounded milliseconds */
$milliseconds = floor($ms);