Rounding values in MEL ?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  04 April 2010
Rounding values in MEL ?


say I have:

float $pos[3];

at the moment I'm rounding the values as follows:

(floor ($pos[0] + 0.5 )
(floor ($pos[1] + 0.5 )
(floor ($pos[2] + 0.5 )

That gives me int's but I want say 3 decimal places and the last value rounded correctly - any tips ?

Also, what is the syntax so I dont have to type out the line three times ?

(floor ($pos[] + 0.5 ) - didn't work like I thought it might

What are the tricks ?

Kind regards
  04 April 2010
this has come up several times before:

search is your friend..
  04 April 2010
global proc int round(float $ANum)
float $n = $ANum % 1;

if ($n >= 0.5) {
$ANum = `ceil $ANum`;
} else {
$ANum = `floor $ANum`;
return $ANum;

//round(3.4); result:3
//round(3.6); result: 4
  04 April 2010
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 11:30 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.