TRAILING DECIMALS - Killing me

I cannot for the life of me get the rounding nodes to work.

The maths.rounds works but then when converted to a string (which I need to do to set the value of an instance text parameter) all the trailing decimals appear again.

And for some reason this warning on the string round up node won’t go away, even when I properly connect it all.

better waYs to do it but maybe this

1 Like

The Round node returns a double, so despite displaying no trailing 0s, it’ll still add them when converted to a string. The Math.Floor and Math.Ceiling nodes return integers, which will work with the String from Object node. You could also put

x:int[]

in a codeblock after the rounding to convert the list of Doubles in a list of Integers.

edit: Oh and the error with that other node is from within the node. A while back people used to name inputs for nodes with data types or protected terms, which several years ago was made invalid. If you did want to fix this, you’d have to edit the node itself, then change the names of the inputs to a more customised term or something else that will not trigger the warning.

5 Likes

Not helpful for now but 2026 has the below node, good times await:

2 Likes

The codeblock from @Hamish is my personal favorite, but I expand on it a bit. It also works in all Dynamo builds I can test at the moment (2.10 to 4.0).

x: int[];
y = x+"";

This image shows the implementation in 2.10, 2.12, 3.0, 3.5, and 4.0:

3 Likes

Interesting, and to get a number with two decimal places, how can I do that? Thank you.

There are very few good reasons to do this, but this should work in all versions:

x: double[];
digits: int;
trim = digits>6?6:digits;
rawStrings = Math.Round(x,trim)+"";
result = String.Substring(rawStrings, 0, String.Length(rawStrings )-(6-trim));

:victory_hand: