-3

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.

ath j
  • 347
  • 2
  • 12

2 Answers2

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