Getting Lowest Whole Integer using Math.Floor Issue

Hi again,

I am trying to round down the values of my outputs so that it is always a whole number if the division yields decimal points.
Example -
16.6667 = 16
15 = 15
14.25 = 14
18.9 = 18

I thought Math.Floor is the right node for this, but when I used it for a division that yielded a whole number (15, in this case), the Output from Math.floor gives 14…

Is there another node that can help me do what I want?

Thank you so much for the help.

Jahzeel

Hi @archjahzzy

That is weird. I can’t recreate that. The bottom (t5) is an alternative to the Math.Floor that is the same thing just in full notation:

My guess is that the Math.Floor function is a result of the rounding of the previous value to 15 from 14.9999999999. Try multiplying by 1 first and see if that adjust the values.

Hi @kennyb6,
I copied the same thing but still gets the same issue.


Tracing back, the issue is with the value 6. I got it from my family’s parameter value but it’s value is 6.000…

Hi @JacobSmall,

You mean something like this?

I tried to multiply 1 to the parameter value (6) , and also to the division (90/6), but still gets the same problem

It’s hard to help because we can’t recreate the problem. This might work as a workaround:

floors

TypeB = 90/TypeBWidth;
TypeBround = TypeB % 1 ==0? TypeB : Math.Floor(TypeB);

Hi kennyb6, I tried to do that but I still get 14.

At the moment, I just used Math.Round for this particular incident while the others are using Math.Floor.

I am attaching both the Revit file with the families I’m using & Dynamo file if you want to take a look. All orange groups are for inputs, and I added a grouped Code block in Pink color. That’s where the issue is.

Thanks,
Jahzeel

Dynamo-SitePlanning_Part3_v2.dyn (177.7 KB)
SG_014_Parametric HousinTry2.rvt (2.0 MB)

1 Like


So the number isn’t exactly 6. Technically there is a 8.8 to the -16th power attached to that 6. So the next question is how many decimal places do you want the widths to be? You can *10, round, divide by 10 to get 5.4, 6.0, etc. and floor will work then.

Like this:
archaddround

2 Likes

Also I forgot that Math.Round has built in arguments for digits, so you could just use TypeBWid = Math.Round(TypeBWidth, 2)

1 Like

Woah. Thanks so much @kennyb6!
This is very helpful, I learned a lot.

Also, do you know the reason why the whole number parameters became like that, does this happen everytime?

Thank you again!

1 Like

This is the first time I have seen it happen, but it happens regardless of what whole number I change the family’s parameter to. If I had to guess, it could be because your family’s units are mm but the project is in meters. Since Revit’s default units are feet/inches, there is probably some conversion error from the family’s mm being changed to inches, then being changed to meters inside the project.

I am not actually sure if this is how Revit handles unit conversions between families and projects but it is just an assumption.

3 Likes

I see…

I seem to be seeing this more often in the graph now. But thanks, I am now able to solve it at least.

The issue might have something to do with the conversion, your’re right but I will see and test it. Thanks again!

1 Like