eye_mew
eye_mew

Reputation: 9133

Multiply percentages in Sass

How do I multiply two percentages together in Sass, in a sensible way?

For example, consider the following declarations:

$num1: 50%;
$num2: 25%;
$num3: $num2 * $num1; 

Here, num3 breaks. What expression can I write to have num3 defined as 12.5%?

Upvotes: 5

Views: 8610

Answers (1)

eye_mew
eye_mew

Reputation: 9133

Figured it out; first you need to convert one of the percentages to a decimal. Here's how it's done:

$num1: 50%;
$num2: 25%;
$num3: ($num2/100%) * $num1;

Upvotes: 17

Related Questions