Hi Guys,

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

Thank you

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.

**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.Add("1.2");
nums.Add("3");
nums.Add("4.567");
nums.Add("8");
nums.Sort((a, b) => (CompareFunc(a).CompareTo(CompareFunc(b))));
foreach (string s in nums)
{
Console.WriteLine(s);
}
}
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.

Cheers.

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?

Cheers

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.

decimals_group.gh (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 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?

Regards

Jeremy