DeadlyNightshade
11-12-2012, 08:16 PM
global float $angle = -45;
// The following will reduce the float to 4 decimals only.
int $negNumber = 0;
if ($angle < 0)
{
$negNumber = 1;
print ("negative number\n");
}
$angle = `match "[0-9]+[.]*[0-9][0-9][0-9][0-9]" (string($angle))`;
if ($negNumber == 1) $angle = -$angle;
print ("Shortened angle value is: " + $angle + "\n");
// Shortened angle value is: -0
This always happen when to $angle variable gets fed a number that lack decimals.
I also get this warning:
// Warning: line 9: Converting string "" to a float value of 0. //
So I understand what is going on - but I don't know what to do to avoid it.
I need to reduce the float $angle variable to -4- decimal and so far I've used "match" to do this - but appearently it's not flawless. Maya doesn't understand that I want to keep it as a float, so it auto-converts it to a faulty string.
// The following will reduce the float to 4 decimals only.
int $negNumber = 0;
if ($angle < 0)
{
$negNumber = 1;
print ("negative number\n");
}
$angle = `match "[0-9]+[.]*[0-9][0-9][0-9][0-9]" (string($angle))`;
if ($negNumber == 1) $angle = -$angle;
print ("Shortened angle value is: " + $angle + "\n");
// Shortened angle value is: -0
This always happen when to $angle variable gets fed a number that lack decimals.
I also get this warning:
// Warning: line 9: Converting string "" to a float value of 0. //
So I understand what is going on - but I don't know what to do to avoid it.
I need to reduce the float $angle variable to -4- decimal and so far I've used "match" to do this - but appearently it's not flawless. Maya doesn't understand that I want to keep it as a float, so it auto-converts it to a faulty string.
