I'm trying to use LESS css to do the following:
width: ((480/1366)*100)+'%';
The problem though is that the output becomes:
width: 35.13909224011713 '%';
How do I make it workable? ie.:
width: 35.13909224011713%;
To convert a decimal to a percentage, multiply by 100 (just move the decimal point 2 places to the right). For example, 0.065 = 6.5% and 3.75 = 375%. To find a percentage of a number, say 30% of 40, just multiply. For example, (30/100)(40) = 0.3 x 40 = 12.
You can add percentages like any other number. Choose a cell to display the sum of your two percentages. In this example, we're going to click and highlight cell C3. In the formula bar, type “=sum” (without quotes) and then click the first result, the sum formula, which adds all numbers in a range of cells.
Add Percentage Style to a Number in Google Sheets Select the cells with decimal numbers (C2:C8), and in the Menu, click the Percentage symbol. 2. To add decimals, (1) select the range with percentages (C2:C8), and in the Menu, (2) click the Increase decimal places icon.
Even though this question is quite old, I want to add a few more examples about adding. Less will set your units to whatever is being operated on.
10px + 20px
will output 30px
(20/200) * 100%
will output 10%
So with units you dont need to concatenate the unit measurement.
I have found that adding 0 helps when you dont know what the unit value might be.
.mixin(@x, @y){
@result: (@x / @y) * 100;
}
.my_class {
.mixin(20, 100);
width: @result + 0%; // you can use any unit here
}
The above class will have a width of 20%. If we added with px, it would be 20px.
It is possible to use string interpolation:
@myvar: ((480/1366)*100);
width: ~"@{myvar}%";
That will output
width: 35.13909224011713%;
Additionally, if you want it to be rounded, you can use round()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With