How to know if renderer.material.GetFloat() exist

I have code like that:

Renderer render = gameObject.GetComponent<Renderer>();
Material material = render.material;
 if (material.HasProperty("_MainTexOpacity"))
{
      float  var = material.GetFloat("_MainTexOpacity");
}

It Works in some materials but when i have some material that have the property “_MainTexOpacity” but dont have any Float, appears this error:

Material doesn’t have a float or range property ‘_MainTexOpacity’
UnityEngine.Material:GetFloat(String)

My question is, have some way to see if the material have float?
I wanna do somethink like that:

Renderer render = gameObject.GetComponent<Renderer>();
 Material material = render.material;
  if (material.HasProperty("_MainTexOpacity"))
 {
       if (material have GetFloat)
       { 
                float  var = material.GetFloat("_MainTexOpacity");
        }
 }

I Find the problem and the solution as well.

I have a Object that have 2 materials in it and i try to acess each one separated just by using .HasProperty(), when i do this, somehow, sometimes the material that doesnt have the “_MainTexOpacity” has property was caught so i put in my condition the .shader.name.CompareTo(), to compare the shader name too, and then i only caught the material that i want.

Thanks to @Owen-Reynolds and @NoseKills for the Help.