I've had loads of problems using UnitValue, and have all but given up on that. I would guess the underlying problem is that JS doesn't really have a concept of "a number as measurement", so -- probably -- the result is a simple string. And you cannot do
var a = 2 * "1 in";
to get the output
$.writeln(a) -> "2 in"
Search this forum; I think I saw a workaround a while ago, using a small function to convert to and from different measurement units.
Sounds as a very serious bug!
It all seems as if UnitValue reverses the subtraction operands when the first term is a Number:
// tested in ID CS4 and CS5 var r = Number(10) - UnitValue(0,'in'); alert(r); // => -10 in alert(r.__class__); // => UnitValue alert(r.value); // => -10 alert(r.type); // => 'in'
Interestingly, we also get:
// tested in ID CS4 and CS5 alert( 10 - UnitValue() ); // => UnitValue -10.000000 alert( -10 - UnitValue() ); // => UnitValue 10.000000
Thanks for pointing that out, linx-eric.