Pi to N Decimal Places

Published by Николай in

Given a number n, write a function that returns PI to n decimal places.

Examples

MyPi(5) ➞ 3.14159

MyPi(4) ➞ 3.1416

MyPi(15) ➞ 3.141592653589793

Notes

  • n will not be above 15, to keep this challenge simple.
  • Round up the last digit if the next digit in PI is greater or equal to 5 (see second example above).
  • The return value must be a number (add suffix -m to returning number), not a string.
Watch a quick demo on how Edabit works.