Formatting numbers during interpolation
See original GitHub issueThe following snippet:
$n: 0;
@while $n <= 10 {
.cls-#{n} { /* ... */ }
$n: $n + 1;
}
Produces a list of classes like:
.cls-0 {}
.cls-1 {}
.cls-2 {}
...
.cls-10 {}
Is there any way to zero-pad the numeric interpolation such that the list of classes have a consistent number of digits like this?
.cls-00 {}
.cls-01 {}
.cls-02 {}
...
.cls-10 {}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
string interpolation - format string output - Microsoft Learn
Any sequence of { or } shorter than the number of $ will be embedded in the output string. As shown in the...
Read more >C# 6 how to format double using interpolated string?
For insensitive interpolation, you can use Invariant from System.FormattableString: Invariant($"at {num}") . See stackoverflow.com/questions/33203261/… – ANeves.
Read more >#{...}: Numerical interpolation - Apache FreeMarker Manual
The numerical interpolation is used to output a number value. If the expression doesn't evaluate to a number, the evaluation ends with an...
Read more >Aligning strings within string.Format and interpolated strings
You specify the alignment component after the number to format and a comma , . For example, the following format string "{value,5}" when...
Read more >3 Must-Know Methods for Python String Interpolation
format (value = price, year_built = year))The house is built in 2000 and worth 100000. In case you are printing decimal point numbers...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@compwright This is slightly crazy, but can be even better solution for you.
If you’re using
libsass
vianode-sass
, you can pass sprintf function to Sass via custom function.sprintf
already has great built-in padding functionality, and even more.Do not forget to cast properly JS type to Sass types, though.
Writing a function to do this is the preferred option. Numeric formatting just isn’t that important in CSS for the most part.