# Calculation does not work with decimal

I have a block with an attribute called Local_height. This is a user input.
Below I have a text where I want to insert a calculation (Local_height + 748), this would be the Global Height.
I have inserted %<748+int(UserText(“block”,“Local_height”))>%.
It works unless the Local height has a decimal point.
See below. local height -3 works, whereas -5.5 does not compute.

I have the feeling I am missing something very obvious but I can’t see it.

Any ideas?, N

PS. Sorry, this is sort of a repeat post, but the first one did not get any replies.

Replace the int with float. Int doesn’t allow fractional parts, float does.

HTH
Jeremy

Thanks a lot Jeremy! that works!
Is there a way to format the number of decimals?

Thanks a lot, N

Yes you can. This is what your `%<748+float(UserText(“block”,“Local_height”))>%` would need to look like to format to two decimal places:

`%<'{:#.2f}'.format(748+float(UserText(“block”,“Local_height”)))>%`

For a different number of decimals just change the 2 to whatever you want.

What we are doing here is using Python formatting commands to display a string with a placeholder - the curly brackets - in it which will be filled with the result of the calculation in the brackets after the format instruction. You can also put boilerplate text in the string if you want, e.g.

`%<'Global Ht: {:#.2f}'.format(748+float(UserText(“block”,“Local_height”)))>%`,
however that is less relevant in Rhino fields because you can build the string outside the <> anyway.

HTH
Jeremy

1 Like

@jeremy5,
Thanks a lot and thank you for the explanation. Excellent.
N

@jeremy5
Out of curiosity:
Do you have a “magic python” way of taking one of the coordinates of the block’s own insertion point instead of using the UserText?
i.e. something like the FAKECODE: 748+float(<PointCoordinate(“ThisBlockInsertion”,“Z”)>)
Cheers, N

Sadly not. Might be worth checking out block related plugins on Food4Rhino.

I thought so. Thanks.