|08 August 2012||#1|
Jr. Technical Artist
Join Date: Jul 2012
Easiest way to cut off decimals from a float?
I've made a procedure that calculates the distance between two UV points using pythagora's theorem, and then it converts that number into pixels and lists this information on a few strings.
Problem is that the variables I have with the results (all floats) usually have HUGE amounts of decimals after them, and I want to display only two decimal numbers.
Now I've searched around the net a bit and doing this seems A LOT harder than it needs to be: MEL doesn't even have a function for this like C++ or well... any programming language really.
So what method is the best (least complex - least amount of code) for just cutting away a few decimals from a float? (not round up!)
|08 August 2012||#3|
Join Date: Nov 2006
you could use a regular expression to return any number of numbers, a period, and then two numbers.
might be a bit complicated to get the regex setup, buts its very little code.
look at the 'match' and 'subsitute' commands.
|08 August 2012||#4|
Join Date: Nov 2005
Good idea rgkovach123
Try this one:
Last edited by backwheelbates : 08 August 2012 at 09:42 PM.
|08 August 2012||#5|
Join Date: Jul 2005
Similar to backwheelbates:
Maya Python Tutorials
Charcoal Editor - Professional Maya Scripting
Keyframe MP - Media Player for Animators
Last edited by zeroeffect : 08 August 2012 at 12:37 PM.
|08 August 2012||#6|
CEO & Founder
Join Date: Feb 2005
could always just cast it over to Python:
python ("'%0.2f' % ("+ $a +")");
where 0.2 is 2 decimal places
Founder & CEO : Red9Consultancy
Red9 StudioPack : Red9 StudioPack GitHub
Author: Autodesk Masterclass 2011 - 'Live Animation Binding'
|08 August 2012||#8|
Join Date: Sep 2003
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.
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
|Thread Closed share thread|