Hi All, I am trying to remove the trailing zeros.000 out of some numbers I have extracted from an Excel. So far I have tried Split, string.remove, (spring nodes) Number.tostring and a few attempts at python. I literally cannot figure out how to do it.
This is the culprit. there are no nulls in the script. The reason I am using String remove is to remove a ] that was at the back of all the numbers in the last list.
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import re
# The inputs to this node will be stored as a list in the IN variables.
str = IN[0]
pattern = re.compile(r'\.000')
# Place your code below this line
# Assign your output to the OUT variable.
OUT = [re.sub(pattern, '', i) for i in str]
Hello @jonny.pyeHMSQY - What version are you in? There was a visual bug that crept into one release that you may be experiencing. If so, this is purely visual and won’t affect the data as it traverses your graph.
The String From Object node has always returned trailing zeros, as you can see in this screenshot from the Dynamo 2.9 release. We can talk about changing this default beahvior
The bug in question was about how many trailing zeros there were that we had tethered to your Number Format in the Preferences Panel unintentionally - which caused issues with understanding accuracy if you had it set to 0 or 0.0 and rounding.
The data itself transmits successfully in all cases as shown below - it’s purely a visual bug. Quite an annoying one for sure, but it’s not destroying your data You can see this here by rehydrating the string into a number and seeing it accurately give the decimally placed number.
I for one would love to change that functionality. It seems logical that when returning a string version of a float you would expect the number of decimal places shown in the float to match the relevant output string…
I’ll just log in in-house in JIRA It’s a sensible change. One of our goals over the past ~3 years has been “Removing the magic” which is basically making what is expected happen. In this case, you don’t expect trailing zeros.
yeah, my proposal is to modify the string from nodes to add an input for standard c# format strings.
The options we offer for numeric preview in preferences will always be limited, and sporadic compared to giving the graph author control - plus, IMO an application level display setting should not be involved at all in generation of actual data / graph execution behavior.
Hi! It seems like you’ve encountered a challenge with removing trailing zeros from numbers extracted from Excel. One approach to consider is using the ‘String.TrimEnd’ method in Python to eliminate trailing zeros. Here’s a sample code snippet:
def trim_zeros(input_list):
return [str(int(float(num))) if ‘.’ in num else num for num in input_list]
This code converts each number to a float, removes trailing zeros, and then converts it back to an integer if it’s a whole number. Adjust it according to your Dynamo script’s requirements. Hope this helps!