I noticed this problem in v1.5.
Since v1.5 you can not pass non-numeric values (not passing isnumber()
) to functions like unit()
that accept only numbers as arguments, even though it worked in earlier versions.
And - numeric values in javascript interpolation were not recognized as numeric by LESS <= 1.6.0, and isnumber(`2`);
would have returned false
.
So, this two put together are the reason why numbers returned by javascript did not work in v1.5, but worked prior v1.5 and work again in LESS v1.6.
But if you need to use it in 1.5 you can "cast the type" by using a function that does accept strings or the "non-numeric numbers" returned by javascript interpolation:
@str: '230'; //or `230`
@getNum: (percentage(@str)/100);
this adds the percentage sign %
at the end ... but it does not really matter if you just want to use it for the number ... as now you can pass it to any function that accepts only numbers ... in your case using unit()
you can change the unit to whatever you like.
margin-left: unit(@getNum , px);
However, an even simpler solution in your case would be to just skip the unit()
function and concatenate the unit to @getNum
:
margin-left: ~'@{getNum}px';
The CSS output would in both cases look like this:
margin-left: 230px;