|
Hi.
Is there anyway to change the precision of a float value manually?
I’m trying to export the normals of a polygon, and fwrite writes out in
double precision by default, but I don’t need that precision.
... float $norm[] = `polyNormalPerVertex -q -xyz`; fwrite($fp, $norm[0]);
...
thanks in advance.
|
|
|
|
You could try the “trunc” command, if you just need the whole number. For example:
trunc 2.82;
// Result: 2 //
trunc -2.82;
// Result: -2 //
Also look at “ceil” and “floor”, but these also just return whole numbers.
If you really need to convert something like 2.82 to 2.8, by just chopping off the last number without rounding you could do some tricks by making the number a string.
string $num = 2.82; string $tokens[]; tokenize $num "." $tokens; //startString is a built in Maya mel script, only available in Mel $firstNumber = startString ($tokens[1], 1); string $singlePrecision = ($tokens[0] + "." + $firstNumber); // Result: 2.8 //
|
|
|