Skip to content

Instantly share code, notes, and snippets.

@placecodex
Created February 18, 2021 22:13
Show Gist options
  • Save placecodex/b87df9a479d4d40479718f83b5f947d6 to your computer and use it in GitHub Desktop.
Save placecodex/b87df9a479d4d40479718f83b5f947d6 to your computer and use it in GitHub Desktop.
obtener porcentaje de ganancia o perdida entre dos cantidades
public function obtenerPorcentaje($cantidad, $total) {
$porcentaje = ((float)$cantidad * 100) / $total; // Regla de tres
$porcentaje = round($porcentaje, 0); // Quitar los decimales
return $porcentaje;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment