Group Numbers as per number of decimal points

Hi Guys,

Good day, is there a way I can group the integers as per the number of decimal points?


Thank you

Could you explain what you want with an example?

The integers don’t have decimal points in your example. The most you would expect to see is 1 for something that can be converted to an integer depending on context (1.000 might be only approximately an integer).

If you mean significant digits, then
is 1.50 different from 1.51?

Hi Nathan,
Thanks for your reply, if my example is not clear then say imagine that I have a random of numbers with decimal values - I what to group separately the one with 2 decimal places, 3 decimal places, no decimal places, etc.

Kind regards.

So you already have a list of strings, not numbers?

The reason I ask is that if they’re numbers, then the decision of how many decimal places to show when you display them is arbitrary.

3.14 can be formatted as “3.14” or “3.140” or “3.1400” or etc.

I think your best method is going to be to create a script component (grasshopper in the pic) and use one of the standard sorts in whatever language you prefer (C#, VB, Python probably), passing a function which returns the number of characters to the right of the decimal point in a string as the comparison to make.

What’s the actual goal or work process here?
Grasshopper seems like an odd tool to pick to solve this problem.

Hi Nathan,

This is a clear example of what I want to achieve, thanks.

EDIT: Our replies crossed in the mail. I see the grouping in your new picture (I just did a sort). Gotta run to dinner. One of the GH gurus here may have an elegant solution to the actual output. Do you want multiple prespecified numbers of places and already have the controls set up?

I’ll just throw this out to see if it’s what you’re trying to do:

void test()
    List<string> nums = new List<string>();
    nums.Sort((a, b) => (CompareFunc(a).CompareTo(CompareFunc(b))));
    foreach (string s in nums)
int CompareFunc(string s)
    int pos;
    pos = s.LastIndexOf(".");
    if (pos == -1)
        return (0);
    //arbitrary decision to rank "1." higher than "1"
    return (s.Length - pos);


Thank you Nathan, is this will do that job as per my image above? cheers.

No, this is just a sort. See my edit: what you actually need as output and the way to set it up is starting to become more clear.

Thank you Nathan, I will give this a try, cheers.

Hi Nathan,

the three groups of numbers from the right hand side are the outputs that I want to achieve out from the left hand side, it is the process which is missing.


Check this post:

1 Like

I changed the topic title from ‘Group Integers as per number of decimal points’ to ‘Group Numbers as per number of decimal points’

Thank you Martin, can we separate or group the items with the same decimal places? as per my image above?


FWIW, If you have computed numbers then make sure you do not pass it through panel and then make decisions based on that. The panel will not represent the numbers ‘correctly’, it does things to it. Always use the data you have computed directly. You can look up the forum about floating point arithmetic and precision. For fun try in python: (0.1 + 0.1 + 0.1) == 0.3

Point is: passing data through Panel and then using the output from it for further calculations and decision making can lead to… unexpected situations.

1 Like

There are many ways to do this but I don’t think regex is going to be much of a help.

Here’s an approach with native components, using the Replace Paths component. (10.7 KB)

Thank you Martin, this is look promising, I will have a try on this, cheers.

1 Like

Hi guys, do you the reason why the decimal component doesn’t give you a consistent result? I may not ask this query if only the decimal component works consistently, cheers.

What component are you referring to?

Hi Martin, this what I am referring to:

Hi Joel,

Just checking the bases…

You have placed 63.1 and 10.20 in different outputs. Does whatever is creating the real input values recognize the distinction, i.e. generate one or two decimal places for a reason and repeatably? And if you display all your input values to a higher level of precision (say six decimal places) do they still show the same number of effective decimal places? If you are working with values that are rounded or truncated, is there still meaning in dividing them up?