This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to get rid of unwanted decimal numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get rid of unwanted decimal numbers" Watch "How to get rid of unwanted decimal numbers" New topic
Author

How to get rid of unwanted decimal numbers

Nick Hallloran
Greenhorn

Joined: Feb 09, 2010
Posts: 19
Hey everyone,

My program runs perfectly except for one thing. On the result side, the numbers have alot of unwanted decimals. Im looking to go to the tenth value. Any help would be appreciated.



Thank you again!
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

I am not sure what exactly you are looking for but in case you are looking for fixed number of decimal places please have a look at DecimalFormat


Pawan Chopra
SCJP - DuMmIeS mInD
Nick Hallloran
Greenhorn

Joined: Feb 09, 2010
Posts: 19
The problem asks me to list numbers from 10,000 to 100,000 on the left side and the PI value for every 10,000. Everything is correct except for all of the decimal numbers that pop up. for example,
10000 multiplied by PI is 3.1415.8999999998. I have read on this else where, and everyone suggests using the decimal format, DecimalFormat("#,###.##"); , but unfortuantely i have not been taught that yet, so i can't use it. I was thinking of using the % operator..but still cant figure out how to do it.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The % (modulo) operator will not help you with this, but I suspect that you mean something else: You can format numbers using String.format(...) or System.out.printf(...), for example:

The Javadoc API documentation of class java.util.Formatter describes the syntax of the format string.

Nick Hallloran wrote:... but unfortuantely i have not been taught that yet, so i can't use it.

You're not allowed to use anything that you haven't been taught? I'd question the quality of your school if learning and discovering things by yourself is discouraged...

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get rid of unwanted decimal numbers
 
Similar Threads
multiples project no output
Recursion Problem
Program like ATM where person enters amount in dollars and cents but program uses int for monies
Help in writing a better program for Vampire numbers
Round Q