• Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting integer into a specific format  RSS feed

 
Hank Harrison
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so I have this bit of code and I'm trying to have the outcome display in format 00.00 format but for some reason it comes out as 0.0.0 format. Can anyone help in getting it formatted to xx.xx format to get the total amount of hours from the calculation of endtime-starttime? it doesnt seem to be taking into account if more than one day passes by either :-( Thanks

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hank Harrison wrote:Ok so I have this bit of code and I'm trying to have the outcome display in format 00.00 format but for some reason it comes out as 0.0.0 format. Can anyone help in getting it formatted to xx.xx format to get the total amount of hours from the calculation of endtime-starttime? it doesnt seem to be taking into account if more than one day passes by either :-( Thanks

OK. Tackling one question at a time:
1. You want 00.00 format, but you slap an integer together with a double, which will always include a '.' when it's printed out.
2. Since we don't know what 'sdt' and 'edt' actually contain, it's difficult to advise. Have you tried printing them out to see what they contain?

My advice: Back up and explain WHAT you're trying to do. What you've shown us is HOW you are doing it - which is plainly not working.

Winston
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hank Harrison wrote:Ok so I have this bit of code...

One other tip: Don't clutter your code with exception logic if you can help it. You have two try blocks that are virtually identical, so why not deal with them outside the method that is doing this? And the simplest way to do that is to have it throw ParseException.

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also...remember there is a difference between how a value is STORED and how it is DISPLAYED. the number '7' is stored as '7'. You can then display it as "7", "SEVEN", "VII", "7.000", "0000000007" or any of about a bajillion other ways you want - but the data stored is still '7'.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: . . . Don't clutter your code with exception logic if you can help it. . . .
That is because OP is using a NetBeans GUIBuilder and it adds that sort of complicated exception handling automatically.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Winston Gutkowski wrote: . . . Don't clutter your code with exception logic if you can help it. . . .
That is because OP is using a NetBeans GUIBuilder and it adds that sort of complicated exception handling automatically.

All the more reason then for NOT doing this type of calculation in that class.

But cheers; I wasn't aware of that. It's a long time since I used Netbeans.

Winston
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: . . . It's a long time since I used Netbeans.

Winston
Same here. I don't think they had that GUI builder that long ago, but am probably mistaken.
 
Hank Harrison
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!