Results 1 to 5 of 5
Thread: adding in array String
- 12-10-2009, 03:29 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 71
- Rep Power
- 0
adding in array String
Hi ... I have an String like +123.321 and I want to add it to an array ..My array like this int[] coordinates = {0,0,0} ..I made it int because when I print ,it must give 0 value if I did not add some thing.. I know that I must conver this String to some int or float but there is a sign + or - and when converting it gives me error .What must I do?
- 12-10-2009, 03:30 PM #2
How do you convert?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 12-10-2009, 04:18 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 71
- Rep Power
- 0
like this
Java Code:String string_to_float="1234.89"; float flt=Float.parseFloat(string_to_float);
- 12-10-2009, 04:19 PM #4
Member
- Join Date
- Nov 2009
- Posts
- 71
- Rep Power
- 0
but it gives error if there is some + or - or something like +1234.43
- 12-10-2009, 04:28 PM #5
Ok, first of all you should post the exact error, because "it gives error" is not very descriptive. This works fine for me:
Output:Java Code:String string_to_float1="+1234.89"; String string_to_float2="1234.89"; String string_to_float3="-1234.89"; float flt1=Float.parseFloat(string_to_float1); float flt2=Float.parseFloat(string_to_float2); float flt3=Float.parseFloat(string_to_float3); System.out.println(flt1); System.out.println(flt2); System.out.println(flt3);
1234.89
1234.89
-1234.89Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
adding to an array
By mayhewj7 in forum New To JavaReplies: 14Last Post: 02-19-2009, 05:41 AM -
Adding numbers in an array?
By hawaiifiver in forum New To JavaReplies: 9Last Post: 01-22-2009, 03:50 AM -
adding <br> html tag to string
By newbieal in forum New To JavaReplies: 7Last Post: 10-14-2008, 02:51 PM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM -
Adding graphics to array
By romina in forum Java 2DReplies: 1Last Post: 08-01-2007, 01:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks