Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 04-11-2004, 10:34 PM   #1
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default truncate

Hey.

Does anyone know how to trucate a number with some degree of control? My float values often look like 0.5505370157 and when I print them out, I'd like to just print 0.55. Maya's trunc command would only print out 0, so that's no good. Maybe a way to round the value off?

Thanks for any thoughts.

-dann
Dann is offline   Reply With Quote
Old 05-11-2004, 01:14 AM   #2
Nimmel
Registered User
 
Join Date: Aug 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is a script for you called roundoff. After saving this to your scripts directory etc. run it with 2 inputs, first the number to truncate and second the number of decimal places you want to truncate it to.

e.g.

roundoff 1.2586541 2

// Result: 1.26 //



/////////////////////////////////////////////////////////////////////////
global proc float roundoff( float $f, int $n )
{
if( $n > 0 )
{
float $roundScale = pow(10,$n);
if( $f > 0 )
return( ((float)(int)($f * $roundScale + 0.5)) /$roundScale );
else
return( ((float)(int)($f * $roundScale - 0.5)) /$roundScale );
}
else
{
float $roundScale = pow(10,-$n);
if( $f > 0 )
return( ((float)(int)($f/$roundScale + 0.5)) *$roundScale );
else
return( ((float)(int)($f/$roundScale - 0.5)) *$roundScale );

}
}
/////////////////////////////////////////////////////////////////////////
__________________
----------------------------------------------
Richard Cheek
http://www.freelance-animation.com
----------------------------------------------
Nimmel is offline   Reply With Quote
Old 05-11-2004, 01:40 AM   #3
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Thanks. I wrote something similar, but was hoping there was a native Maya command I was overlooking. However, your code is nicer than mine, so I'm gonna use it. Thanks again.
Dann is offline   Reply With Quote

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.