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

use a Python node:

import clr
from Autodesk.DesignScript.Geometry import *
dataEnteringNode = IN
OUT = “(” + str(round(IN, 2)) + “)”

2 Likes

Hello everyone,
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!

1 Like

hi guys, what about dropping all decimals after the point?
other way than maybe converting to String and cutting it before the point “.”?

I keep searching the internet but to no avail.

Rounding?

Roundinng rounds stuff, i want to discard info.

If i have 2.6 and 2.3 one will be rounded to 3 and other one to 2, right?

You can round down though. Use `Math.Floor`.

Can you give an example of a number you have, and what you want it to be? Like do you just want 2.6 to be 2 and 3.4 to be 3? Is something else?

I think he is trying say, above 2.5

Will consider 3 and below 2.5

Will consider 2.

As @Nick_Boyts replied math.floor and math round will do the same.

Hello! Yes! This is what i was looking for. A bit silly. Thank you!

2 Likes

You might also want to look at bankers rounding / round-to-even with the following overload:

``````Math.Round(number, 2, MidpointRounding.ToEven);
``````