This project has moved and is read-only. For the latest updates, please go here.

Setting Decimal property of Object [V8]

Dec 3, 2014 at 1:36 PM
Hello. I'm trying to set a value to a decimal property of an object. Setting integer values works but for decimals "Error: Invalid property assignment" error thrown.

Works Fine
MyObject.Price = 1
Invalid property assignment thrown
MyObject.Price = 1.5
Dec 3, 2014 at 2:09 PM
Edited Dec 3, 2014 at 6:31 PM

JavaScript numbers are floating-point and therefore not implicitly convertible to decimal (see here for more information).

You can assign a decimal property as follows:
engine.AddHostObject("host", new HostFunctions());
engine.Execute("MyObject.Price = host.toDecimal(1.5)");
By the way, your first example works because ClearScript converts JavaScript numbers to integers when doing so results in no data loss, and integers are implicitly convertible to decimal.

Good luck!
Dec 3, 2014 at 4:50 PM
Thank you very much for the detailed explanation. That worked great.