Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created March 31, 2015 18:08
Show Gist options
  • Save gavilanch/cb2c3248f326c773d80f to your computer and use it in GitHub Desktop.
Save gavilanch/cb2c3248f326c773d80f to your computer and use it in GitHub Desktop.
Nth decimal of Pi
/// <summary>
///This function returns the nth decimal of Pi
/// </summary>
/// <param name="lugar"></param>
/// <returns></returns>
private int ObtenerDecimalNdePi(int lugar)
{
double Pi = Math.PI;
double Potencia = Math.Pow(10, lugar);
double PotenciaFloor = Math.Pow(10, lugar-1);
double PiPorPotenciaFloor = Math.Floor(Pi * PotenciaFloor) * 10;
double resultado = Pi * Potencia - PiPorPotenciaFloor;
return (int)Math.Floor(resultado);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment