Results 1 to 4 of 4
Thread: formatting numbers in output
- 05-27-2010, 07:26 AM #1
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
formatting numbers in output
i'm using Formatter class.
int x = 2010;
System.out.format("Result: %d", x);
how do i remove first two integers from x?
to have the following output // -> "10"
i have read Formatter and i understood how to perform "a right shift", have a zero-padded result and so on, but could not find anything on how to remove integers from the left side of the result.:confused:
please, help.
- 05-27-2010, 07:32 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
- 05-27-2010, 11:49 AM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
Formatter is intended to format output, not change its value.
An alternative way to JosAH's suggestion is to trim off the two leftmost characters after formatting:Java Code:System.out.print("Result: "+ String.format("%d", x).substring(2));
- 05-27-2010, 06:43 PM #4
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Formatting numbers or decimals (around comma)
By Joris in forum Advanced JavaReplies: 1Last Post: 04-22-2010, 05:46 PM -
Formatting output somewhat like a table
By latereg in forum New To JavaReplies: 3Last Post: 04-06-2010, 06:44 AM -
Need help formatting File Output
By aaroncarpet in forum New To JavaReplies: 2Last Post: 11-26-2009, 05:26 PM -
Need help formatting output and some code
By A5i19 in forum New To JavaReplies: 6Last Post: 11-09-2009, 04:58 AM -
Truncating decimal numbers in the output
By gbade in forum New To JavaReplies: 2Last Post: 11-21-2008, 06:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks