I need convert "100% - 1" to 300 - 1 where 300 - canvas width? How to eval (batch) this operation?
//for example:
var value = batch("100% - 1", canvas.width); //Must 299, because canvas.width is 300
var secondary = batch("50% + 10", canvas.width); //Must 160
//where first argument - arithmetic operation, second - relativity value.
This question is not from the scope of science fiction, but a very serious and real issue.
Update! But if need just convert percentage?
var value = hack("75%", 300); //Must 255
var operation = hack("30%", 100) + 10; //Must 40
var end = hack("1em", somearg); //EM?
Update2! What a will, if i use new Function("a", "b", "return (%%Expression%%)") instead of eval?
For example:
var operation = "90% - 10";
To:
new Function("a", "return ((a * 90 / 100) - 10)");
How to made it?
var anything = (canvas.width * (percent / 100)) + somenumber;?