Math Round Behaviour

Hi,

I’m trying to round some numbers using the Math.Round node. It has an strange behaviour (see attached image).
Does anybody know why is not working or another way to round a number?

Thank you.

Use Math.Ceiling node instead of Math.Round

Hi @robert12546358,
I would like to preserve 2 digits.

This is all expected behavior. Your lists all have nulls or empties which is why you’re getting warnings. Rounding converts your values to doubles and then converting them to a string shows the trailing zeros (that are otherwise hidden). Using Math.Ceiling or Math.Floor converts the values to integers so there are no trailing zeros. If you need to keep 2 decimal places then you’ll have to remove the trailing zeros after the fact. I believe there are some custom nodes that already do this but I can’t remember which. A very quick python script would work as well.

1 Like

I think you are searching something like that.

import clr
import math
input = IN[0]
formatted = ['{:.2f}'.format(math.floor(i*100)/100) for i in input]
OUT=formatted
1 Like

There’s a node in the data-shapes package that converts to string and let’s you choose how many decimals.

Hi @robert12546358,

Thanks for helping.
I did more or less the same but this python node doesn’t work with empty values. So I had to add a dummy node to deal with “blank” values. What are these “blank” values, empty values?

Try None instead of 0.

Hi @_Vijay,

None as a string? How can I set None instead of 0?