• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get rid of unwanted decimal numbers

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Nick Hallloran
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
My cellmate was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic