I want to add 00 before a int example 1.How can i do that.I know that there is a way to do that using if condition and then concat() but i want a cleaner method for converting 1 to 001.
Asked
Active
Viewed 56 times
-3
-
you want to change it to decimal 1,00 or you want 100 ? – Taha Jun 27 '16 at 16:08
-
Create a static utility method in Java doing what you want. Register it as a JSP EL function in a JSP tag library. Invoke the JSP EL function from the JSP. http://docs.oracle.com/javaee/5/tutorial/doc/bnahq.html#bnaio – JB Nizet Jun 27 '16 at 16:12
-
Or just use `00${theValue}`, if that's what you want. – JB Nizet Jun 27 '16 at 16:40
-
I want to change it to 001 – ath j Jun 27 '16 at 16:43
2 Answers
0
you can do it with javascript
example
function myFunction() {
var num = 15;
var n = num.toString();
var str2 = "00";
var res = n.concat(str2);
document.getElementById("demo").innerHTML = res;
}
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

Taha
- 1,072
- 2
- 16
- 29
0
<%
int i =1;
String s = "00"+i+"";
out.println(s);
%>
you can do it by this in jsp tag

Lucky Sharma
- 173
- 6
-
Thanks it worked but I think that the int i was converted to string.I want just that.Is that true?? – ath j Jun 27 '16 at 16:46
-
yes '+' do concat and convert to String http://stackoverflow.com/questions/47605/string-concatenation-concat-vs-operator – Taha Jun 27 '16 at 16:55