Tag Archives: number
Little tricks: string padding in Javascript
I just found this little trick to zero pad numbers in Javascript. It is also applicable to padding with any character, not just zeros. var n = 123 String("00000" + n).slice(-5); // returns 00123 ("00000" + n).slice(-5); // returns 00123 (" " + n).slice(-5); // returns " 123" (with two spaces) Found here.
Equivalent of parseInt() in Freemarker
Programming languages have methods to cast integers to strings and strings to integers, but usually is had to find equivalents to parseInt(), a Javascript function that basically removes all non-numeric characters from a string and returns the resulting integer. Today, while working on a Freemarker template, I had to convert strings like “40 ms.” and [...]
