(solved)Error in math extensions

In Maths PI = 3.14...

this is float value so you need to return it into float type like this,

       @SimpleFunction(description = "")
       public float Pi() {
          return (float)Math.PI;
       }
1 Like

do you have any documentation about that?

may be but really as it said it is a "double" value

i did as
@SimpleFunction(description = "")
public double Pi() {
return (float)Math.PI;
}

1 Like

thats why error mentioned -double to int

1 Like

This one is not possible

correct code is

@SimpleFunction(description = "")
public double Pi() {
   return (double)Math.PI;
}

i think you are right @HIFI_APPS

1 Like

any way thanks both i got this idea from you both
@preetvadaliya,@salman_dev

First you need to learn about data types some keyword and OOPS concepts

I think @HIFI_APPS is right because I saw this code :

@SimpleFunction (description = "Calculates the area of Circle. Input should be in same unit.")
  public double AreaOfCircle ( double radius )
  {
return (double) (Math.PI * (radius * radius));
  }

i only know three types int,string,float now double where can i learn all

yes it worked

there are many types of datatypes in java

  1. Primitive datatypes
    Boolean
    char
    byte
    short
    int
    long
    float
    double

  2. Non-primitive datatypes
    String
    objects
    etc..

this is proof that @HIFI_APPS is right

i remember all this in childhood except short,objects

i don't have any idea to mark solution to anyone,both helped me in this if i marked 1 other will be sad so let it be without a mark

there difference between float and double size of float is 4 byte = 32 bit and size of double is 8 byte = 64 bit.

give the mark to yourself :innocent: :rofl:

1 Like

PI is defined as a double in Java (ref) and you don't need to cast the return to double since everything will be promoted to double for the math operations since they involve at least one double.

2 Likes

please remember to follow the naming conventions

Taifun

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.