First of all, I am aware that to turn a unitless value into one with a unit I can multiply a unitless value by a single unit:
$value: 25 * 1px; // 25px
However I would like to know if there is any way to do this when the unit is dynamic.
$unit: rem;
$value: 23;
.Box {
// Try interpolation
$united-value: #{$value}#{$unit};
value: $united-value; // Appears to be correct
// Check it is actually a number using unitless
check: unitless($united-value); // $number: "23rem" is not a number for `unitless'
}
Obviously if I was to make the value of $unit
1rem
I could just multiply as in my first example, but is there a way to do this with a naked unit value.
Sassmeister here
[Edit] As @zessx correctly states, CSS doesn't care about the type and will treat both string and number values identically in this case. However I need to perform operations on the value once the unit has been appended.
[Edit] I'm not sure how I can be any clearer. I don't want / need a function that uses multiplication under the hood. I already know how that works and how to do it. I am interested if there is a way to take a unitless value and a unit and make a united number out of it.
Is there a a way to take px
and 22
and make 22px
that is a number and can have mathematical operations performed on it? Any answer that shows me how I can take 1px
and 22
and do the same thing is not answering the question I'm asking.