How to limit the number of decimals in a displayed float?

The situation is as follows:

I have made a Text shape which can display the distance between two dummies. The following script is embedded in the Kerning parameter of the Text shape to make it update the text shape runtime.

$ArrowLineNumber06.text=(distance $DummyTipArrow11 $DummyTipArrow12 /10) as string + “cm”

The problem I have is that I am not interested in a up to six decimal precision (like 1.342434) I just need one or two decimals (like 1.3). How do I limit the number of decimals in a displayed float?

Thanks for any help.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexus's picture

if you want only one decimal

if you want only one decimal

a = distance $DummyTipArrow11 $DummyTipArrow12
a = floor (a*10)
a = a/10
$ArrowLineNumber06.text = a as string + "cm".

decapitator's picture

Sounds a bit harsh with all

Sounds a bit harsh with all the variable setting.. Id do it more like $ArrowLineNumber06.text = ((floor ((distance $DummyTipArrow11 $DummyTipArrow12) * 10)) / 10.) as string + "cm"
Comes down to the same thing, except that from what I know from other languages setting variables continuesly slows the progress down alot and besides its nice and short all in one :)

alexus's picture

It's very simple a =

It's very simple

a = distance $DummyTipArrow11 $DummyTipArrow12
a = floor (a*100)
a = a/100
$ArrowLineNumber06.text = a as string + "cm".

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.