I`m trying to get percentage in lesscss file with 2 digits accuracy.
In lesscss file
@w: round(((100-((12-5)*3.8))/(12/5))*100);
width: percentage(@w/10000);
Compiles to width: 30.580000000000002%;
What I`m doing wrong?
My logic is very simple:
Step 1: Get the “not right” digit 30.580000000000002
Step 2: 30.580000000000002*100 = 3058.0000000000002
Step 3: round(3058.0000000000002) = 3058
Step 4: 3058/10000 = 0.3058
Step 5: percentage(0.3058) = 30.58
You are not considering that floating-point computation is done in binary, where there is no exact representation of 1/10000. Therefore:
(It does not matter if LESS uses an ECMAScript implementation like JavaScript, as long as computation is based on IEEE-754 double-precision floating-point numbers.)
However, you should not bother about that.
is perfectly Valid CSS.