1

I have a variable that sets a percentage:

@var-a: 50%;

And another that is a fixed width:

@var-b: 100px;

I want to calculate @var-c as below:

@var-c: (@var-a * @var-b);

I expected 50px, but actually get 5000px. What am I doing wrong?

2
  • 1
    If you just want half of @var-b you should just have @var-a : 0.5, percentages are used in the context of the client page width. Commented Aug 24, 2013 at 18:22
  • @var-a is a height variable, so I would assume it needs to stay as a percentage? Commented Aug 25, 2013 at 11:01

1 Answer 1

1

Less calculations use the numbers regardless of the units. If you know that @var-a will be in percentages, you could just do something like this:

@var-c: unit(@var-a / 100 * @var-b, px);

using unit() allows you to control the output unit.

You can also use guards in addition to do something else if @var-a isn't a percentage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.