Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • pi

    Posted on April 2nd, 2009 RubyLove No comments

    Returns the value of PI to 14 (default) decimal places. This precision can be altered in the php.ini file.

    PHP

    echo pi();
    // => 3.1415926535898

    Ruby

    puts Math::PI;
    # => 3.14159265358979

    In the code above, PI is actually a constant of the Module Math. PHP also has a constant which stores the approximate value of PI - M_PI.

    PHP

    echo M_PI();
    // => 3.1415926535898

    Leave a reply