Community
Bifrost Forum
Welcome to the Bifrost Forum. This is the place for artists using Bifrost to ask and answer questions, browse popular topics, and share knowledge about creating effects procedurally using Bifrost. You can also visit the Bifrost Community on AREA to download an array of ready-to-use graphs, read Bifrost news and updates, and find the latest tutorials.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to keep the number with two decimal places?

21 REPLIES 21
SOLVED
Reply
Message 1 of 22
g2m.agent
1328 Views, 21 Replies

How to keep the number with two decimal places?

I have a float number that needs to be converted into a String.
Such as 43.30000024
I want it to keep two decimal places: 43.30
I found that the built-in nodes round_to_nearest, round_to_floor, round_to_ceiling cannot retain decimals.

so what is the solution?

 

maya_5kRckl6XT2.png

21 REPLIES 21
Message 2 of 22
mjcg91
in reply to: g2m.agent

Here's how I would do it using string. To increase the number of decimal, you can just increase the "size" on the sequence node.

clamp_decimal_with_string.jpg

Maxime Jeanmougin - Technical Artist
https://maximejeanmougin.com

Join the Bifrost Addicts community on Discord:
https://discord.gg/bifrost-addicts
Message 3 of 22
mcw0
in reply to: g2m.agent

Old fashion solution is to multiply by 100.  Convert to int.  And multiply by 0.01.

Message 4 of 22
mjcg91
in reply to: mcw0


@mcw0 wrote:

Old fashion solution is to multiply by 100.  Convert to int.  And multiply by 0.01.


That's actually the most efficient solution.

Maxime Jeanmougin - Technical Artist
https://maximejeanmougin.com

Join the Bifrost Addicts community on Discord:
https://discord.gg/bifrost-addicts
Message 5 of 22
g2m.agent
in reply to: mcw0

It doesn't seem to work. the problem seems to "number_to_string".

maya_zZNx1VAEW7.png

Message 6 of 22
mcw0
in reply to: g2m.agent

Why are you using a "number_to_string" after multiplying by 100?  I'm not in Maya right now so I can't verify this but can't you use a value node and set it to integer and connect the output of multiplying by 100 to that to convert to an integer?

 

Oh, I see what you are saying.  "number_to_string2" is where the issue comes from.  Yes, that's common when dealing with floats.  hhhmmm...

 

There are no truncate functions?

Message 7 of 22
g2m.agent
in reply to: mcw0

another example: "number_to_string" turns float "1.61" into string "1.61000001".

maya_brfrost graph_number_to_string_problem.png

Message 8 of 22
mcw0
in reply to: g2m.agent

Unfortunately, that's how floats behave.  0.0 != 0

 

 

Message 9 of 22
mcw0
in reply to: g2m.agent

Again, I'm not in Maya so just thinking out loud.  There must be a modulus function in Bifrost.  After you convert to integer, take the modulus of the integer to 100 (integer % 100).  That result is your decimal.  Now subtract that from your integer to get your whole number.  Now use "build_string" and use the whole number, "." and the modulus result!

Message 10 of 22
g2m.agent
in reply to: mcw0

Basically, I want to rebuild the After Effects Text layer in Maya. plug in any String or Number to display it on the screen (in the viewport).

I use the methods provided by Bruce.Lee and mspeer to input the String into the Python Expression slot of Type. The Python Expression slot only accepts Strings. The original post is here: https://forums.autodesk.com/t5/bifrost-forum/how-to-show-mesh-infomation-into-quot-type-quot-or-quot...

Message 11 of 22
g2m.agent
in reply to: mcw0

So mjcg91's method may be the only way.

Message 12 of 22
mcw0
in reply to: g2m.agent

I'm not sure what the AE text layer is.  But if you want to display any string or number in the viewport, you don't need Bifrost to do that.  I used a simple Python script.  I'm not on my work computer but I can post it tomorrow.

 

But just curious, did the modulus approach not work?

Message 13 of 22
g2m.agent
in reply to: mcw0

this is my connection:

maya_JJzjYoMRAr.png

 

When the number is less than -1 and greater than 0.01, the result is correct.

when the number is -0.017, the result is 0.1

when the number is 0.057, the result is 0.5

 

“Integer part” cannot recognize +0 and -0

"decimal part" cannot recognize 057 and 57

Message 14 of 22
mcw0
in reply to: g2m.agent

The +/- issue can be handled with a conditional.  But the "number_to_string" removing the first zeros is unavoidable but can also be handled with conditionals.  😞  I thought for sure we had it solved.  😞 😞

 

A shot mask like the one the plugin builds could be scripted with MEL.  I have scripts that could be "Frankensteined" into what you need (camera frustum and text editing).

 

But maybe the creator of the plugin could add that feature.  It wouldn't be difficult to do.

Message 15 of 22
mcw0
in reply to: g2m.agent

DOH!!!  As I typed my last reply, the solution hit me.  It will take a few more nodes but it's definitely doable.  Plug your input value into an "if" node.  If value is less than zero, add a "-" sign at the start of the "build_string" node.  And then for your decimal portion, another "if" node.  If less than 10, add a "0" after the "." in the "build_string" node.  By the way, the "0" should not be a "number_to_string" as that will probably not recognize the zero.  Just set it in the "build_string" node.

Message 16 of 22
g2m.agent
in reply to: mcw0

I think this graph is more complicated than mjcg91's graph and not easy to read.

Message 17 of 22
g2m.agent
in reply to: mjcg91

I found a bug. when the input is an integer, it will produce the wrong results. such as

1 => 1.1

2 => 2.2

......
the new graph can solve this issue.

the only disadvantage is that it cannot round decimals.

number_to_string_v3number_to_string_v3

 

 

Message 18 of 22
mcw0
in reply to: g2m.agent

Capture13.PNG

 

This appears to work and handles negative inputs.  "split_string" uses "." as the separator.

Message 19 of 22
mcw0
in reply to: mcw0

OOPS!  This works!

 

Capture14.PNG

Message 20 of 22
g2m.agent
in reply to: mcw0

Unfortunately, it still doesn't work.

You can build this rig to test your graph.

1. create a cube, sphere, anything

2. select it, Create->Annotation...

3. in Node Editor, connecting like this:

maya_HzSnuBTKmR.png

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums