Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

format float value precision with mel format commad

format float value precision with mel format commad

batarg
Advocate Advocate
682 Views
2 Replies
Message 1 of 3

format float value precision with mel format commad

batarg
Advocate
Advocate

just making custom distance label with annotation node.

i need to format precision to get rid of extra values.. it will be great if it could be done within format command with syntax like in python (```"{:10.2f}".format(3.1415926535)```)

 

by default command  `format -s 3.1415926535 "^1s"` rounds to ```3.141593```

0 Likes
Accepted solutions (1)
683 Views
2 Replies
Replies (2)
Message 2 of 3

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

The MEL format command is just for formatting strings, not numbers.

In MEL there are a couple of ways to do this:

The easiest solution is to just call Python from MEL.

 

float $value = 3.1415926535;
float $rounded = python("round(" + $value + ", 2)")

 

Otherwise, if you need a pure MEL solution you will have to use some lower level Math functions since there is no built-in round function.

 

float $value = 3.1415926535;
float $dec = pow(10,2); // second arg is required number of decimals
float $rounded = floor($value*$dec+0.5)/$dec;

 

Brent McPherson
Principle Engineer
Message 3 of 3

batarg
Advocate
Advocate

sadly that format command is so narrow in mel.

thank you @brentmc  for the tip! i will use your mel variant!

0 Likes