# Excel´s mround function in grasshopper

Hi.

I have been struggling to find a similar Excel´s mround function in grasshopper.

Mround rounds up, away from zero, if the remainder of dividing number by multiple is greater than or equal to half the value of multiple.

Example:

Rounding the numbers
5.76 - 6.00
5.74 - 5.50

In excel, the expression for these example are:
=mround(x;0.5)

Any help?

Pufferfish has a round to nearest component.

1 Like

2 Likes

Hey Amir

The item 1 is not rounding correctly… should be 6.00…

Hi Rickson.

I´m going to try, but this is a simple excel/google spreadsheet formula… shouldn´t need a plugin for this…

actually, no. it would be 5.85 if f=0.05
check the screenshot & try it out yourself!

round_nearest.gh (5.5 KB)

edit: i guess you edited your post?

3 Likes

i think mround always rounds up…
CEILING works in grasshopper expressions. (which may be helpful here… i’m not at a computer to mess around with it)

Hey Amir

I tested your formula… not quite working, as the item 4 should round to 0.65, not 0.6 (it should round up). Any thoughts?

In order to get that list on the right, I copied and pasted from google sheets using the mround (=mround(x;0.5))

Thanks

as jeff_hammond suggested, ceiling works.

1 Like

The result you have is not unexpected. It all depend on double precision and other problem. Tell me which number between 0 and 2 is nearest to 1? You will say me none or the two. Algorithm round has to choose one number. It is.possible that grasshopper algo slightly different than excel one.

Mround rounds up, away from zero, if the remainder of dividing number by multiple is greater than or equal to half the value of multiple.

I looked with Excel and Grasshopper.
You will have 0.65 with Grasshopper if you add 0.0000000000001 (or less) to 0.625 ! Excel must have a <= and Gh (.Net surely) <.

.Net round has two MidpointRounding modes. .Net’s Default is .ToEven which is called bankers rounding but you can set it to .AwayFromZero

So like

Math.Round(2.5, MidpointRounding.AwayFromZero);

will result in 3.0 instead of 2.0.

1 Like

I just updated Pufferfish and the V2.1 has a “Round To Factor” component for this.

2 Likes