Jump to: Board index » General » Fusion

Help reducing decimal in counter

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

3drogelio

  • Posts: 3
  • Joined: Thu Jan 10, 2019 5:37 am
  • Real Name: Rogelio Guzman

Help reducing decimal in counter

PostThu Jan 10, 2019 5:44 am

I only need 2 decimal places in the counter. It seems by default to have more than 10 decimal places. How do you reduce them?
Offline

Frank Feijen

  • Posts: 167
  • Joined: Tue Dec 13, 2016 10:04 am
  • Location: Vilvoorde, Belgium

Re: Help reducing decimal in counter

PostThu Jan 10, 2019 8:06 am

Where did you find/How did you create that counter?
I'm guessing that it's easy to fix with an expression?
Offline
User avatar

Bryan Ray

  • Posts: 2478
  • Joined: Mon Nov 28, 2016 5:32 am
  • Location: Los Angeles, CA, USA

Re: Help reducing decimal in counter

PostThu Jan 10, 2019 4:52 pm

Assuming you're using something like a Text+ node, you need to format the string like so:

Text( string.format("%.5f", [number source]) )

In the string.format() function, the first argument determines how to handle the number. In this case, %.5f means that a floating-point number will have up to five digits after the decimal. To give it only two decimals, the string is %.2f.

The number source is whatever is feeding the Text. So it's probably whatever is currently in your Text() expression.
Bryan Ray
http://www.bryanray.name
http://www.sidefx.com
Offline

3drogelio

  • Posts: 3
  • Joined: Thu Jan 10, 2019 5:37 am
  • Real Name: Rogelio Guzman

Re: Help reducing decimal in counter

PostThu Jan 10, 2019 9:16 pm

I am new to expressions and did some searching online. The way I ended up approaching it was the following:
added Test+ node and set the Styled Text to expression and then linked(Controlled) that to the Number In 1 slider of a CustomTool1 node to control the animation of the numbers. I need it to go up and down between 2 sets of range numbers. This seemed to get me 90% of the way there. I just don't need all the decimals. I only need 2. See screen grabs

It would be nice if there was a setting where I change the appearance to just show only 2 or 1 decimal place

Bryan, I tried the expression you gave but not sure how to animate the exact numbers I need. I would need it to go from 2.2 to 1.2 for about 50 frames and then go back to 2.2 after another 50 frames. I would probably need this to repeat a couple of times. Since I could not figure that out, I did it the way I explained above.

Any thought or suggestions?
Thanks
Rogelio
Attachments
Text+Node.PNG
Text+ Node
Text+Node.PNG (40.82 KiB) Viewed 4405 times
Decimal issue 2.PNG
Decimal with to many places
Decimal issue 2.PNG (38.15 KiB) Viewed 4405 times
Decimal issue 1.PNG
Decimal starts of right
Decimal issue 1.PNG (46.74 KiB) Viewed 4405 times
Offline

3drogelio

  • Posts: 3
  • Joined: Thu Jan 10, 2019 5:37 am
  • Real Name: Rogelio Guzman

Re: Help reducing decimal in counter

PostSun Jan 13, 2019 4:53 pm

Does anyone have a solution on how to get rid of the extra decimals?

Thanks
Rogelio
Offline

moggers

  • Posts: 10
  • Joined: Mon Jun 28, 2021 8:23 pm
  • Real Name: Gareth Morgan

Re: Help reducing decimal in counter

PostSun Feb 12, 2023 6:16 pm

I appreciate I'm late to the party here as this is a few years old but I wanted to say thanks to @Bryan Ray as the solution was perfect for me.

I had this originally to count seconds on my clip
floor(time/comp:GetPrefs("Comp.FrameFormat.Rate"))

however then I decided I wanted to have decimal places but the above was limited to the zero decimal places. Using the expression you shared I entered
Text( string.format("%.5f", floor(time/comp:GetPrefs("Comp.FrameFormat.Rate"))))
replacing the [number source] with what I would have as the number source. I then realised that this would just produce 1.00, 2.00, 3.00 and so on and then realised I needed to remove the floor so all the decimals came into the input so the string.format could take it to two
making the final expression
Text( string.format("%.2f", time/comp:GetPrefs("Comp.FrameFormat.Rate")))

Thank you!!! :D

Return to Fusion

Who is online

Users browsing this forum: No registered users and 44 guests