Results 1 to 2 of 2
  1. #1
    oran0007 is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Question [Q] - pi as a float

    Forgive me if this has been asked, but I searched for pi and Math.PI and class and float and couldn't find anything relevant.

    Problem as follows:

    input:

    a number which is a radius

    output:

    area and circumference of the circle with input as radius
    volume and surface area of the sphere with input as radius

    I got a working class, but when I attempted to change the variables to floats, in the interest of learning, it errored out. The reason is that Math.PI yields a double. I tried:

    float pi = Math.PIF

    That doesn't work. The only way I was able to have a working class using floats, I had to initialize pi as follows:

    pi = 22/7F

    Is there a way to use Java's Math.PI as a float?

  2. #2
    oran0007 is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Re: [Q] - pi as a float

    Someone gave me the solution at XDA Developers.

    float pi = (float) Math.PI

Similar Threads

  1. regarding int and float
    By lakshmibvaraprasad in forum New To Java
    Replies: 2
    Last Post: 07-24-2011, 08:30 PM
  2. string to float
    By Sungron in forum New To Java
    Replies: 3
    Last Post: 02-02-2010, 09:23 AM
  3. Working with float
    By dardar in forum New To Java
    Replies: 8
    Last Post: 01-27-2010, 08:29 PM
  4. Float vs. Double
    By javanub in forum New To Java
    Replies: 1
    Last Post: 11-23-2008, 12:11 PM
  5. Class float
    By Peter in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 01:17 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •