0

I am using DefaultHttpClient to send data to web... To send data m using following code block:

nameValuePairs.add(new BasicNameValuePair(name, value)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

but namevaluepairs only take string.. I need to send integer value with this.

Please guide.. Thanks in advance.

1 Answer 1

1

Use Integer.toString(integerValue). For example:

nameValuePairs.add(new BasicNameValuePair(name, Integer.toString(5))); 

Edit, further to the comments below:
And for a float you can use:

nameValuePairs.add(new BasicNameValuePair(name, Float.toString(10.82522f))); 
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the reply... I tried this earlier but in case of values like 10.84522 it converts to 1084522 so please suggest how to resolve this issue...
This is because 10.84522 is not an integer but a floating point value. Use Float.toString(10.84522). (Anyway, Integer.toString() does not convert 5.5 to 55, you must have done something else)
check which locake you are running in.. for example with german locale 125.25 == 12,525 and 125,25 == 125.25.. the , and the . are interchanged in that locale.. this was just an example you need to figure out which locale your jvm is running in.
it seams like "culture problem" on server side :) ... in many countries "." it's decimal separator ... but sometimes it's thousand separator ... many programming languages using local culture setting to parse numbers/dates/etc. ...
What I meant above is that String str = Integer.toString(5.55); does not even compile: "The method toString(int) in the type Integer is not applicable for the arguments (double)"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.