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

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. :smiley:

Thank you!

Here is the solution,

2 Likes

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

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