# SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

 Register FAQ Members List Calendar Mark Forums Read

 04-11-2004, 09:34 PM #1 Dann Registered User     Join Date: Feb 2003 Location: Los Angeles Posts: 695 Thanks: 0 Thanked 2 Times in 2 Posts 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
 05-11-2004, 12:14 AM #2 Nimmel Registered User   Join Date: Aug 2004 Posts: 24 Thanks: 0 Thanked 0 Times in 0 Posts 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 ----------------------------------------------
 05-11-2004, 12:40 AM #3 Dann Registered User     Join Date: Feb 2003 Location: Los Angeles Posts: 695 Thanks: 0 Thanked 2 Times in 2 Posts 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.

 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

## \$34

Month-to-month billing

## \$87

Billing every 3 months
 \$29/month Unlimited access to all videos Project files to download Easy to cancel at anytime Save \$5 per month or \$15 in total compared to monthly billing with this package.

## \$288

Billing every 12 months
 \$24/month Unlimited access to all videos Project files to download Easy to cancel at anytime Save \$10 per month or \$120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.