# Numbers with Decimals

**URL:** <https://forum.dynamobim.com/t/numbers-with-decimals/12136>\
**Category:** Uncategorized\
**Created:** [May 30, 2017, 4:38pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136 "2017-05-30T16:38:56Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Hurtubise](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daniel_hurtubise/32/146534_2.png) [@Daniel\_Hurtubise](https://forum.dynamobim.com/u/Daniel_Hurtubise)\
**Post date:** [May 30, 2017, 4:38pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/1 "2017-05-30T16:38:56Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/4/84ac70a5f5acd6fb9fa0457bfde4be5042ee6236.png)

---

<div class="post-metadata">

**Author:** ![Daniel\_Hurtubise](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daniel_hurtubise/32/146534_2.png) [@Daniel\_Hurtubise](https://forum.dynamobim.com/u/Daniel_Hurtubise)\
**Post date:** [May 30, 2017, 4:43pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/2 "2017-05-30T16:43:17Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/4/94478ddfe1de40658426b55b2ff3e24a2e1f459d.png)

---

<div class="post-metadata">

**Author:** ![Joan\_Moreto](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/joan_moreto/32/19433_2.png) [@Joan\_Moreto](https://forum.dynamobim.com/u/Joan_Moreto)\
**Post date:** [May 30, 2017, 5:33pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/3 "2017-05-30T17:33:15Z")

</div>

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.

> [@Rounding Values](https://forum.dynamobim.com/t/rounding-values/1478):
>
> When i connect List.GetItemAtIndex to StringFromObject my values changes to 6 decimal places. How do i change StringFromObject Values to zero decimal places? &nbsp; [Untitled]

---

<div class="post-metadata">

**Author:** ![Daniel\_Hurtubise](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daniel_hurtubise/32/146534_2.png) [@Daniel\_Hurtubise](https://forum.dynamobim.com/u/Daniel_Hurtubise)\
**Post date:** [May 31, 2017, 1:25pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/4 "2017-05-31T13:25:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alvpickmans](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alvpickmans/32/41236_2.png) [@alvpickmans](https://forum.dynamobim.com/u/alvpickmans)\
**Post date:** [May 31, 2017, 2:45pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/5 "2017-05-31T14:45:33Z")

</div>

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](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).  
 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/8/f8898b195b0b6fc6ca63f2483139b2f9169b8979.PNG)

---

<div class="post-metadata">

**Author:** ![Adrian\_Crisan](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@Adrian\_Crisan](https://forum.dynamobim.com/u/Adrian_Crisan)\
**Post date:** [May 31, 2017, 4:03pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/6 "2017-05-31T16:03:23Z")

</div>

@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)) + “)”

---

<div class="post-metadata">

**Author:** ![snduy11](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@snduy11](https://forum.dynamobim.com/u/snduy11)\
**Post date:** [July 10, 2019, 1:10pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/7 "2019-07-10T13:10:51Z")

</div>

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

 ![2019-07-10%2015_07_59-Dynamo](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/2/628c9aea62d6df237c702655989a018aa6741d9e.png)

---

<div class="post-metadata">

**Author:** ![Anton\_Huizinga](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/anton_huizinga/32/155377_2.png) [@Anton\_Huizinga](https://forum.dynamobim.com/u/Anton_Huizinga)\
**Post date:** [July 10, 2019, 6:55pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/8 "2019-07-10T18:55:42Z")

</div>

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

Have a look here:

> [@Force 2 digits after the decimal point](https://forum.dynamobim.com/t/force-2-digits-after-the-decimal-point/37487/5):
>
> This is a perfect base for a Custom Node: [NumberToString.dyf](https://forum.dynamobim.com/uploads/short-url/8W5mFixK7OrRleep4AXot1wukFj.dyf) (10.1 KB)

---

<div class="post-metadata">

**Author:** ![snduy11](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@snduy11](https://forum.dynamobim.com/u/snduy11)\
**Post date:** [July 11, 2019, 7:01am UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/9 "2019-07-11T07:01:05Z")

</div>

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Daniel\_Hurtubise](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daniel_hurtubise/32/146534_2.png) [@Daniel\_Hurtubise](https://forum.dynamobim.com/u/Daniel_Hurtubise)\
**Post date:** [July 18, 2019, 5:35am UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/10 "2019-07-18T05:35:42Z")

</div>

Ended up being a custom node in Data-Shapes

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/0/b049a9c8c72d49126fc5bd9565c322858003189e.png)

---

<div class="post-metadata">

**Author:** ![bogdan.petrescu63URX](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bogdan.petrescu63URX](https://forum.dynamobim.com/u/bogdan.petrescu63URX)\
**Post date:** [February 1, 2021, 12:15pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/11 "2021-02-01T12:15:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [February 1, 2021, 2:58pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/12 "2021-02-01T14:58:56Z")

</div>

Rounding?

---

<div class="post-metadata">

**Author:** ![bogdan.petrescu63URX](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bogdan.petrescu63URX](https://forum.dynamobim.com/u/bogdan.petrescu63URX)\
**Post date:** [February 1, 2021, 3:45pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/13 "2021-02-01T15:45:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [February 1, 2021, 3:47pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/14 "2021-02-01T15:47:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)\
**Post date:** [February 1, 2021, 5:10pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/15 "2021-02-01T17:10:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![\_Vijay](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/_vijay/32/91307_2.png) [@\_Vijay](https://forum.dynamobim.com/u/_Vijay)\
**Post date:** [February 1, 2021, 5:39pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/16 "2021-02-01T17:39:58Z")

</div>

I think he is trying say, above 2.5

> [@bogdan.petrescu63URX](#):
>
> 2.6

Will consider 3 and below 2.5

> [@bogdan.petrescu63URX](#):
>
> 2.3

Will consider 2.

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

---

<div class="post-metadata">

**Author:** ![bogdan.petrescu63URX](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bogdan.petrescu63URX](https://forum.dynamobim.com/u/bogdan.petrescu63URX)\
**Post date:** [February 1, 2021, 8:49pm UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/17 "2021-02-01T20:49:19Z")

</div>

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

Thank you!

---

<div class="post-metadata">

**Author:** ![\_Vijay](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/_vijay/32/91307_2.png) [@\_Vijay](https://forum.dynamobim.com/u/_Vijay)\
**Post date:** [February 2, 2021, 11:36am UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/18 "2021-02-02T11:36:18Z")

</div>

Here is the solution,

 ![Math.Round](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/9/e9c0b200583eee982e95da0f2d0dae601d60906d.png)

---

<div class="post-metadata">

**Author:** ![romankris](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@romankris](https://forum.dynamobim.com/u/romankris)\
**Post date:** [March 30, 2021, 7:09am UTC](https://forum.dynamobim.com/t/numbers-with-decimals/12136/19 "2021-03-30T07:09:01Z")

</div>

You might also want to look at bankers [rounding](http://net-informations.com/q/faq/round.html) / round-to-even with the following overload:

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

```
