Results 1 to 6 of 6
Thread: Substring double values?
- 06-05-2011, 07:54 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 12
- Rep Power
- 0
Substring double values?
I'm trying to substring a double value but I tried .substring but i believe that's only for strings.
And I'd also like to round the numbers up a tiny bit.
for example
4.079691454585337
rounded up to 4.08 without showing the rest of the numbers.
Could anyone put me in the right direction for this. Thanks a bunch!
-
You can do this any number of ways, but first of all, you are right, subString is for Strings only. Now as to your problem, it can be solved with a DecimalFormat object or the static String method String.format(...).
- 06-05-2011, 08:37 PM #3
You can see what methods a class has by reading the API doc for that class.I tried .substring but i believe that's only for strings.
If you are printing the numbers and want to control what is printed, see the printf() method.
- 06-06-2011, 03:37 AM #4
Member
- Join Date
- Jun 2011
- Posts
- 12
- Rep Power
- 0
I'm not sure what I'm doing wrong. I've checked the printf class and followed a tutorial but I get a problem with the script.
Here's my code:
Is there a reason why there comes with an error with this? I can't see why, I've followed the tutorial and it seems correct.Java Code:System.out.printf("%.1f \t %f", year, price);
Any pointers would be greatly appreciated!
- 06-06-2011, 03:43 AM #5
You forgot to post the full text of the error message.Is there a reason why there comes with an error with this
- 06-06-2011, 03:54 AM #6
Similar Threads
-
find the unique values of a double array
By tyang in forum New To JavaReplies: 3Last Post: 09-11-2011, 02:47 PM -
Double with no negative values.
By vahini in forum New To JavaReplies: 11Last Post: 05-05-2011, 09:07 AM -
Removing the double values?
By Lund01 in forum Advanced JavaReplies: 13Last Post: 11-17-2010, 11:34 AM -
Pick up a double quoted substring
By java_user in forum New To JavaReplies: 1Last Post: 01-08-2010, 05:12 PM -
mutliplicatio of double values
By katkamravi in forum New To JavaReplies: 2Last Post: 04-13-2009, 02:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks