Reputation: 2071
I am trying to pad array elements with zero if they are less 10. That is if I have elements in an array 1,2,12 I want to print 01,02,12.I am trying to do this in the scala template in the playframework. So what I tried now was to use if and else statemnts in scala to see if the element is less than 10 and then pad a zero.
@for(element <- myarray){
@if(element.getValue < 10){@element} else{@element}
}
myarray is a Uint8 array which is defined by me and getValue is function in the UINT8 class. Hpowever it keeps telling me that not found: value element
. Is there any other way out to just pad with 0's for me?
Upvotes: 0
Views: 705
Reputation: 55798
Don't forget that Play's view is also a Scala function, so you can easily perform operations directly in the code, for an example use common way for formatting integer to string with leading zeros (as found in other question):
@for(i <- 1 to 1000){
@("%04d".format(i))<br>
}
Upvotes: 1