Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanna make number with zero behind it just like this 0835
here's my code :
Java
new Response.Listener<String>() {
                   @Override
                   public void onResponse(String response) {
                       try {
                           JSONObject obj = new JSONObject(response);
                           JSONArray movieArray = obj.getJSONArray("data");

                           ///get last data only///
                           for (int i = 0; i < movieArray.length(); i++) {
                               JSONObject movieObject = movieArray.getJSONObject(i);
                               getNo_pengajuan_full nomor = new getNo_pengajuan_full(
                                       movieObject.getInt("no_pengajuan_khusus"));
                               no_pengajuan.add(nomor);
                           }
                           getNo_pengajuan_full item = no_pengajuan.get(no_pengajuan.size() - 1);

                               nopengajuan.setText(String.valueOf(item.getNo_pengajuan_full() + 1));
                               hideDialog();

                       } catch (JSONException e) {
                           e.printStackTrace();
                       }
                   }


What I have tried:

When i tried to make this code
Java
nopengajuan.setText(String.valueOf("0" + item.getNo_pengajuan_full() + 1));


the output is 08351
Posted
Updated 5-Nov-20 15:13pm
v2

1 solution

Quote:
I wanna make number with zero behind it just like this 0835

Did you tried to replace
Java
nopengajuan.setText(String.valueOf("0" + item.getNo_pengajuan_full() + 1));

with
Java
nopengajuan.setText(String.valueOf("0" + item.getNo_pengajuan_full()));

[Update]
Quote:
nah..
in code
nopengajuan.setText(String.valueOf("0" + item.getNo_pengajuan_full() + 1));

is used for add up a number...

nah..
if item.getNo_pengajuan_full() is 835
then item.getNo_pengajuan_full() is promoted to "835" because of the "0"
So, calculation is
"0" + 835 + 1 => "0" + "835" + 1 => "0835" + 1 => "0835" + "1" => "08351"
 
Share this answer
 
v2
Comments
Komang Putra 5-Nov-20 21:33pm    
nah..
in code
nopengajuan.setText(String.valueOf("0" + item.getNo_pengajuan_full() + 1));

is used for add up a number...

just like this..

example
item.getNo_pengajuan_full() = 835
then 835 + 1 = 836

Maybe i just tried this..
nopengajuan.setText('0' + String.valueOf(item.getNo_pengajuan_full() + 1));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900