Skip to content

Commit 9ad775f

Browse files
committed
Merge pull request #1152 from xzyfer/fix/1140
Don't truncate trailing 0s on integers when precision is 0
2 parents b943915 + 299e2a7 commit 9ad775f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

inspect.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,11 @@ namespace Sass {
424424
// if after applying precsision, the value gets
425425
// truncated to zero, sass emits 0.0 instead of 0
426426
bool nonzero = n->value() != 0;
427-
for (size_t i = d.length()-1; d[i] == '0'; --i) {
428-
d.resize(d.length()-1);
427+
size_t decimal = d.find('.');
428+
if (decimal != string::npos) {
429+
for (size_t i = d.length()-1; d[i] == '0' && i >= decimal; --i) {
430+
d.resize(d.length()-1);
431+
}
429432
}
430433
if (d[d.length()-1] == '.') d.resize(d.length()-1);
431434
if (n->numerator_units().size() > 1 ||
@@ -444,6 +447,9 @@ namespace Sass {
444447
// use fractional output if we had
445448
// a value before it got truncated
446449
if (d == "0" && nonzero) d = "0.0";
450+
// if the precision is 0 sass cast
451+
// casts to a float with precision 1
452+
if (ctx->precision == 0) d += ".0";
447453
// append number and unit
448454
append_token(d + n->unit(), n);
449455
}

0 commit comments

Comments
 (0)