Grasshopper- Decimal digit problem, Solved

I have a C# component here which converts rhino text to a grasshopper text. I am trying to input this text as a number. But while doing so, it is trimming decimal places of numbers to one place which is ending with zero (as visible in image)

Problem.3dm (486.5 KB) (14.7 KB) . I need this text to be converted to numbers while keeping decimal places intact.

That’s impossible. Floating point numbers do not store significant figures. You need to operate on numbers and format them into texts later.

I thought about it. but there are certain numbers which end with 1 decimal and I need them intact too. Formatting or rounding will change decimal places of all numbers in list. In fact as you can see here, to even round it, I need to put it through number component.

Then you need to work out another logic that fits your requirement. Maybe you can keep track of decimal digits through the calculation.

Grasshopper uses 64-bit floating point numbers to store fractional values, as @gankeyu said, this number format does not include any information about significant digits.

There is another number format used in .NET called decimal. This number type is used primarily for financial calculations. Decimal number do have some support for significant data, in that the decimal values 1, 1.0, 1.00, 1.000, etc. are all actually different and retain their decimal places. However there are limits to what can be done here as well.

It sounds like you need to create your own data type which is smart enough to do what you need. This almost certainly requires creating a GHA project in Visual Studio (or other .NET compliant IDE) instead of using just the script components.

However if you store your data into your own type instead of standard types, you won’t be able to use any of the standard maths components. You’ll have to write your own Addition, Subtraction, Multiplication, … components if you need to perform those kinds of operations on your numbers.


One C# component, one python component and some conditional expressions did the trick. Thanks David for pointing out possible solutions.