Numbers with Decimals

Good afternoon everyone,
i have a list of numbers (Level.Elevation) that i want to “encapsulate” between parenthesis ()

When the numbers gets out of Math.Round i do have 2 decimals.
t2 =Math.Round(t1, 2);

But as soon as i try to encapsulate it into () i end up with 6 decimals
t2 = “(” + Math.Round(t1, 2) + “)”;

Any idea how to keep the 2 decimals?

Thanks

Im using this for now, still would like to understand the logic :slight_smile:

Hi Daniel
I don’t know about the logic of it but when you turn a number into string it gets 6 decimals. Have a look at this thread.

That’s what i’m doing but still interested in understanding the logic :slight_smile:
I guess a string is always 6 decimals

That might have something to do with how doubles/floats are converted to string in c#
https://msdn.microsoft.com/en-us/library/kfsatb94(v=vs.110).aspx

A solution would be to trim out the extra zeros after converted, considering that you have already rounded to two decimals (and the other 4 will be zeros anyway).

3 Likes

@Daniel_Hurtubise:

use a Python node:

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
dataEnteringNode = IN[0]
OUT = “(” + str(round(IN[0], 2)) + “)”

2 Likes

Hello everyone,
Do you know about this Node?
Thank you

That is a custom node that does not work. Maybe it can’t handle lists input.

Have a look here:

Thanks a lot!

Ended up being a custom node in Data-Shapes