Android: converting String to int to subtract two string

Jyotishgher Astrology
By -
0
Android: converting String to int to subtract two string



Suppose we are getting value from Database in String format and our task is to subtract 



try {
jObj = new JSONObject(response);
int userId = jObj.getInt("success");

int coupne_amount = jObj.getInt("coupne_amount");//any integer value

if (userId == 1) {


//Suppose this is String 
String fixedrate = Totalprice.getText().toString().trim();


now convert that into integer:

int fixedpriceafterremove= Integer.parseInt(fixedrate.substring(5));
String final_ = String.valueOf(fixedpriceafterremove - coupne_amount);
final results will be printed here

Totalprice.setText(final_);

// Toast.makeText(hotel_details.this, final_, Toast.LENGTH_SHORT).show();
} else {
int errorMsg = jObj.getInt("error_msg");
}
} catch (JSONException e) {
}

Post a Comment

0Comments

Post a Comment (0)