This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Test  RSS feed

 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just finished my class test at uni, and i submitted it, so this is not cheating!!!

I completed it all, but only problem i had was when i printed the carbontax, i couldnt get it to 2 decimal places. Bah mite lose a mark for it.. Any ways i could have done this, so i can do it in future?

 
Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you get extra marks if you do something like this:
Locale locale = Locale.CANADA;//or wherever you are
String string =
NumberFormat.getCurrencyInstance(locale).format(<your float> );

123.45678 should read like this: $123.46
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

above code could be a solution.

Depending on application the solution may vary. In structs framework it have built in funcyoionality for formatting.

In java tiger you can use C language kind of formatting using %d, %f etc.
http://java.sun.com/developer/technicalArticles/releases/j2se15/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!