regex - "IllegalFormatConversionException: d != java.lang.String" when padding number with 0s? -
i had working code yesterday, in exact form of:
int lastrecord = 1; string key = string.format("%08d", integer.tostring(lastrecord)); which pad nicely 00000001.
now kicked notch twokeychar getting string table , lastrecord getting int table.
as can see concept same - convert int string , try pad 0s; however, time following error:
java.util.illegalformatconversionexception: d != java.lang.string the code below:
string newpk = null; string twocharkey = gettwocharkey(tablename); if (twocharkey != null) { int lastrecord = getlastrecord(tablename); lastrecord++; //the println below outputs correct values: "ru" , 11. system.out.println("twocharkey:"+twocharkey+"record:"+lastrecord+"<"); //now make ru00000011 newpk = string.format("%08d", integer.tostring(lastrecord)); newpk = twocharkey.concat(newpk); } i feel must have typed wrong, because there no reason break since last time when worked. help/hint appreciated! thank you!
you don't need integer.tostring():
newpk = string.format("%08d", lastrecord); string.format() conversion , padding.
Comments
Post a Comment