• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to setup a decimal point for a result?  RSS feed

 
Jason Hart
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now it displays a number like this "$25.0" and I want it to display it like this "$25.00" and don't know how to do it. Can anyone help me?
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What have you tried? Post the code and please UseCodeTags (←click)
 
Jason Hart
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Welcome to the Ranch.

What have you tried? Post the code and please UseCodeTags (←click)


Haven't tried anything yet, I am only a couple weeks into learning java so don't know much at all. This is the program I am making for class.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can refer the oracle tutorial
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jason,

I'm a bit about other things - code readability (also, next time please UseCodeTags when you post your code, Knute already mentioned that).
The way you choose your variable names, adds confusion to your code reader and most important - to yourself.
Your comment would be absolutely redundant if you'd pick more descriptive variable name and it would be a better practice rather than keep adding comments after each statement and make code less readable. Try to come up with something more descriptive (applied to all current variables).
Try to avoid indenting code like this, it makes your code even less readable. Look for a tutorial, how to indent code properly. I found for you one tutorial on JavaRanch.
Thats it from me for now. Welcome to the Ranch


 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added the code tags and also broken the long lines and doesn't it look better
I suggest you leave out most of those comments because they don't tell us anything we don't already know.

I am afraid you are not writing object‑oriented code. If you have salespeople you should have a Salesperson class. Then you can have name and salesAmount as its fields
 
Paweł Baczyński
Bartender
Posts: 2077
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I suggest you leave out most of those comments because they don't tell us anything we don't already know.

In some classes teachers require comments on each line to know a student understands the code he or she submitted...
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:
Campbell Ritchie wrote:I suggest you leave out most of those comments because they don't tell us anything we don't already know.

In some classes teachers require comments on each line to know a student understands the code he or she submitted...
Well, not many of us could prove the necessity of such a comment as:
Campbell Ritchie probably meant (and I agree), that OP should concentrate on code quality first, rather than adding comments (which do not say more than code itself) after each statement.
Pawel, you can be right also I'm not going to judge teacher, don't have right.


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!