'not show decimals in PHP Value?
I have a web made in laravel, livewire and I need to hide decimals in variable: 'valor' => $countPoblacion->poblacion] since it is currently showing decimals in all values.
class ConteoPoblacion extends Conteo
{
protected function cargarDatos($args = null)
{
if ($this->tieneArgumento('idMunicipio', $args))
{
$countPoblacion = Distrito::select(
DB::raw('SUM(poblacion) as poblacion'),
DB::raw('SUM(km2) as km2'),
)
->where('id', '=', $args['idMunicipio'])
->first();
return [
['nombre' => 'poblacion', 'valor' => $countPoblacion->poblacion],
['nombre' => 'densidad (hab/km2)', 'valor' => $countPoblacion->poblacion / $countPoblacion->km2],
['nombre' => 'superficie en km2', 'valor' => $countPoblacion->km2],
];
} else if ($this->tieneArgumento('idSeccion', $args))
{
$countPoblacion = Distrito::select(
DB::raw('SUM(poblacion) as poblacion'),
DB::raw('SUM(km2) as km2'),
)
->where('seccion_id', '=', $args['idSeccion'])
->first();
return [
['nombre' => 'poblacion', 'valor' => $countPoblacion->poblacion],
['nombre' => 'densidad (hab/km2)', 'valor' => $countPoblacion->poblacion / $countPoblacion->km2],
['nombre' => 'superficie en km2', 'valor' => $countPoblacion->km2],
];
}
}
}
Solution 1:[1]
Did you try rounding the numbers? Using any of these functions
round()
floor()
or
ceil()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | simPod |
