Round number like Revit

Hello,

I’m created a script that get all rooms , group the rooms using a parameter that is the flat number, sum the surface of the rooms of each flat, and then write the surface of the whole flat in the living room of the appartement.

Until there, no problem

BUT

I have an issue with rounding.

I have a room that revit shows with an area of 11.050 sqm.
This value is rounded to 11.1 in Revit, and to 11.0 in Dynamo.

In fact, the crazyest part is that, with dynamo, I can see that the value of this room is not 11.050 but 11.049999999956 and I don’t understand why Revit round this to 11.1 …

Do you have any idea of how I can mimic Revit rounding system to get a consistent value between revit and dynamo, and be sure that the total value of each appartement is the same in plans and in schedules ?

Thank you

Under the revit settings for Units, there is something called precision. This controls the revit rounding of the numbers.

Revit rounding could be incorrect, so you should properly check and think this through.

If you want to match what is in revit you can use the “Rounding.Ceiling+” from the clockworks package

Thank you for answering my question.

I couldn’t find the precision setting in Revit under Unit settings, could you be more specific of where is this setting ?

The issue with the node you propose from Clockwork Package is that in this case, All the values will be rounded to ceiling, and not only those that Revit mis-round, …

And so even if 11.04999 get the good value, all the others values are unconsistent with what revit does…

Hi,

Actually, this is a problem that has existed for many years. You just need to write a formula in the schedule table. In this way, the surface on the plan and the schedule table will be synchronised. I think there is no need to use dynamo for this job.
formula : round(surface / 0.1) * 0.1

1 Like

Sorry it is rounding setting, you have to go to the unit in question(eg Area) then click on the format button and it will have a rounding setting there.

You probably need to add further logic then to cover it for other situations

Yes, this is what I made for the rounding issues in schedules, but now, I want to write the same value in plans, and this is where dynamo comes to the rescue (or almost)

I will try to add some decimals in the rounding setting and then see what’s going on values on the revit side

Just to clarify, this is two different things happening at the same time.

  1. Revit will round values to the specified precision of the project units for that parameter. This can be overridden in schedules and other places. If you want to match the value shown in the schedule, you have to know what the rounding is for that column (or maybe get the value directly from the column).

  2. Revit and Dynamo use different methods for calculating precision values. Sometimes, due to rounding and whatnot, Dynamo will return a “more precise” but mismatched value. It’s just a rounding thing, almost never enough to actually make a difference in any calcs (we’re talking immeasurable precision). Just round it if it bothers you.

1 Like

import math
v = IN[0]
c = (math.ceil(v*100)/100)  
f = (math.floor(v*100)/100) 
OUT = c,f

Ref: rounding - How to round to 2 decimals with Python? - Stack Overflow

2 Likes

To just use Python’s round function can do:

import math
# A list of numbers
numbers = IN[0]
# A new list to store the rounded numbers
rounded_numbers = []
# Loop through the numbers and round each one
for number in numbers:
  # Round the number and append it to the new list
  rounded_number = round(number)
  rounded_numbers.append(rounded_number)
OUT = rounded_numbers

or with precision

import math
# A list of numbers
numbers = IN[0]
precision = IN[1]
# A new list to store the rounded numbers
rounded_numbers = []
# Loop through the numbers and round each one
for number in numbers:
  # Round the number and append it to the new list
  rounded_number = round(number, precision)
  rounded_numbers.append(rounded_number)
OUT = rounded_numbers

Ref: Bing AI Chat

1 Like