Remove trailing zeros


Please show me the way to remove trailing zeros in number shown in the below screen shoot

Trailing Zero


Any help would be appreciated

1 Like

If you always have the same number of trailing zeroes (and they don’t occur anywhere else in your string), it’s quite easy:


If not, you would probably have to work with regular expressions…


Hi Andreas Dieckmann,

Nice to receive good solutions from you again
Yes, it’s quite easy indeed, it well satisfied my case
However, for further understanding, could you please show me how if the number of trailing zeros fluctuates

Many thanks

:slight_smile: Okay, I’ll humour you. Here’s how you could achieve it for varying lengths of trailing zeroes using regular expressions:


Actually, come to think of it, “\d+.[0-9]” would be better…

1 Like


Hi Andreas Dieckmann,

I have tried out your instruction, it is useful
Also, I would like to raise another case for you to brainstorm
It would be much more perfect if you have a solution for the case shown below as well

Many thanks

Trim Trailing Zeros




To those who want to trim trailing zeros same as my case
By utilizing available nodes in conjunction with Andreas’s advice, I have found a workaround for this issue finally
So I should now put an end to this topic
However, any better idea would be greatly appreciated
Trim Trailing Zeros


If you got those trailing 0’s by using Dynamo’s “String from Object” node, maybe a neater solution would be to try Python’s number to string conversion:



Extremely smooth!!
It’s a lot better than my clumsy set of nodes
Your python script has just let me know that I am newbie
Thanks for your kind sharing




Very good code, Dimitar.

the Python’s number to string conversion seems keep 1 zero direct after the decimal point, is there a way to resolve this problem?


Hi Chen,

I rolled a revised version of the above called “Number.ToString” into spring nodes package. Give it a try:



Thanks Dimitar! It works perfect.



I haven’t touched Dynamo for a year since my first plunge into this marvelous tool and this community and I’m just restarting to get my feet back in the game…

I’m running Dynamo on Revit 2016 and used the “Number.ToString” node but it doesn’t seem to remove the zeros like in your post to Chen back in May '16.

My Attempt
Parameter Value is my L/s (metric model) flow converted to Cubic Feet/seconds (by Revit/Dynamo) which I want to convert back to L/s but with no trailing zeros:


Looks like you’ll first have to round up your numbers to appropriate for your need.

Hi @Jonathan_Roy

Why not just convert to Revit Internal Units.

Here is the DYN file For Jonathan (IneternalParameterUnits).dyn (3.2 KB)

1 Like

Thanks for the different solutions and I tried them out with different results.

I first tried @Kulkul’s solution with the python script and it gave me what I was looking for as an end solution. The “how did he get that answer?” in me still remains clueless when I quickly open the python script to take a look. I guess I’ll have to disect it later with the “Revit Lookup” addin you pointed me too a while back to try and understand what is going on.

Then I tried @Dimitar_Venkov’s suggestion regarding rounding up. I only found the “Math.RoundUpToPrecision” node in the packages I have installed, but I didn’t like the results for my application.
To follow the same idea, I then looked up “Rounding” on the forum and found a 2015 Thread about the subject that @Kulkul had brought up and tried the soluon provided by @john_pierson. It also gave me a good solution and since the package is made up of OOTB nodes I think :wink: I’d be able to understand how he was able to make it.

I’ll close by saying that someone has to make a MEP Python 101 class. I’m pretty sure it would be popular and in demand. I know I would, because we’re looking to do more engineering with Revit than is possible with OOTB .

1 Like

@Jonathan_Roy Next time start a new thread. Thanks :slight_smile:

Will do. I wasn’t sure if i should start a new thread on the same subject or continue on this one since it was in the same direction. I should’ve started a new one and linked the different posts in them?
Thanks again, and see you on a new thread… soon :wink:

1 Like

For what you’re trying to do, getting Revit’s display unit value makes a lot more sense, so I’d go for Kulkul’s suggestion. But for future reference, if you’re trying to get the string representation of a floating point number, my suggestion was this: