How to force use the float method instead of the double method?

Asked

Viewed 74 times

0

How to force use the float method instead of the double method?

public static void Dividir(double dividendo, double divisor)
{
    //https://www.codeproject.com/Tips/579137/Division-By-Zero-Doesnt-Always-Raise-An-Exception
    if (divisor == 0)
        throw new DivideByZeroException();
}

public static void Dividir(float dividendo, float divisor)
{
    var resultado = dividendo / divisor;
}

To call the method with the float arguments as I do?

1 answer

2


You need to call the passing method floats by parameter, ex:

float num1 = 1.1;
float num2 = 2.2;
Dividir(num1, num2);

In case you already have the numbers and it’s not float, just give a cast:

int num1 = 1.1;
int num2 = 2.2;
Dividir((float)num1, (float)num2);
  • 2

    I went through another way that I discovered that is Divide(10.0f, 10.3f);

  • 1

    If you pass just like this Split(10.0, 10.0); falls in double

Browser other questions tagged

You are not signed in. Login or sign up in order to post.