Grasshopper GetData functon will not save the input into a float type

The following code runs with error:

        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddNumberParameter("Float", "F", "Float number.", GH_ParamAccess.item);
            pManager.AddNumberParameter("Double", "D", "Double number.", GH_ParamAccess.item);
        }

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            double dbnumber= 0;
            float flnumber = 0;
            if (DA.GetData(0, ref dbnumber) == false)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Double number not saved!");
                return;
            }
            if (DA.GetData(1, ref flnumber) == false)
            {
                 //the code always stops here with this runtime message
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Float number not saved!");
                return;
            }
        }

Is it a thing in Grasshopper that you can’t save data in float ? Or is it a bug?
I already solved my problem with a simple typecast, I’m just asking out of curiosity.

I think GH_Number is always a double so that you cannot do this.

1 Like