Trailing Zeros when importing info from Excel

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.

image
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.

any help most appreciated.
Map Autodesk Build to Revit.dyn (36.0 KB)

@johnny.buccolaY4MEH unfortunately your image is not legible, so could you please let us know what you’re trying to do?

Are you looking to use these numbers as a String? Or as a Number? Where do you want to put them?

I am looking to remove the .000 from the rear end of the string list marked-up in the image. As mentioned they have been extracted from an Excel.

let’s try with small python script like this :slight_smile:

# 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]

image

2 Likes

Many Thanks!! but no ball I’m afraid.

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.

1 Like

I think I’m right in saying that the bug was patched with Dynamo 2.19 shipped with the Revit 2024.2 update right @solamour ?

If you’re in Revit 2024.1 @jonny.pyeHMSQY I’d recommend the update (not only for this but the other improvements included within this version).

There’s two things at play here:

  1. 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 :100: talk about changing this default beahvior :slight_smile:

  1. 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.

  1. 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 :pray: You can see this here by rehydrating the string into a number and seeing it accurately give the decimally placed number.

3 Likes

Yep that was it, thank you :slight_smile:

2 Likes

I like that phrase, poor thirsty string haha.

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…

Worth taking this discussion elsewhere?

1 Like

I’ll just log in in-house in JIRA :slight_smile: 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.

1 Like

Great stuff. I’ll add this to the list of things that I can say to people in my old man voice “Back in my day…”

1 Like

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.

3 Likes

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]

Example usage:

input_numbers = [‘1.000’, ‘2.500’, ‘3.120’, ‘4’]
output_numbers = trim_zeros(input_numbers)

Result:

output_numbers = [‘1’, ‘2.5’, ‘3.12’, ‘4’]

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!

Oh hello ChatGPT :wave: :laughing:

2 Likes