# Need two decimals

## Recommended Posts

Hi,

one of those questions where the answer is propably easier than binding your shoes but you didn´t have a coffee for several hours and therefor your brain is frozen (thats me...)

My Problem: Im am using a font sop to display the distance an object is traveling in the scene (simulating a digital display). I just don´t get it right so that it is 1.) only displaying 2 decimal points like 25.76 and 2.) displays 34.00 and not 34 as it is automatically doing.

Any help will be highly appreciated.

##### Share on other sites

for 1) you can use trunc like so:

trunc(100*\$ATTRIBUTE)/100

but you are right, when there is an end-zero it will not display it, so I don't know the answer to 2) unless you want to use Python, in which case it is probably is quite easy.

##### Share on other sites

As an hscript expression in the 'Text' field of a FontSOP?

Maybe you can try:

``padzero(2,trunc(\$NUM))`.`padzero(2,trunc(round(frac(\$NUM)*100)))``

Where you'd replace '\$NUM' with whatever the number is that you need to represent, and change the two constants ('2') with the amount of zero-padding you want on either side of the decimal point (which the power-of-ten on the right side should also match, of course).

Cheers.

##### Share on other sites

Neat! I was still thinking in numbers, should be thinking in characters instead, nice!

##### Share on other sites

I've been trying this function, but with the attempt of only showing 1 decimal. However I do it, it seems to sometimes show .10 instead of .0.

How do I get around that?

##### Share on other sites

Using Python:

`'Time: %.1f' % hou.time()`

Using VEX sprintf():

```// Detail wrangle.

s@num = sprintf("%.1f", @Time);```

in Font node:

`Time: `details("../attribwrangle1", "num")``

format_font.hipnc

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account