• 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

double variable and place values

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there a way to restrict the place value of a double variable? I'm writing a change counting program, and I'm getting a number out to the bajillionth place. For reference, here is the code



TextIO is an input/output external class I'm using, designed by David J. Eck. I doubt its the problem, but the coding for it is currently above my skill.

I ran multiple searches, but google fails me on this one guys
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raine Andrews wrote:is there a way to restrict the place value of a double variable?



A few options are ... (1) use the printf() method, along with appropriate formatting, (2) use NumberFormat to convert it to a string and print the string.

Henry
 
Raine RaineAndrews
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I'll google up those terms and see what I can learn!
 
Raine RaineAndrews
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh my... just a tad bit over my current skill
 
Raine RaineAndrews
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it! I deleted the quarter, dime, nickle, and penny variables, and instead plugged in the value times 100 where the variables used to be. If I divide that at the end by 100, it gives me a nice round number ^.^
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raine Andrews wrote:Got it! I deleted the quarter, dime, nickle, and penny variables, and instead plugged in the value times 100 where the variables used to be. If I divide that at the end by 100, it gives me a nice round number ^.^



That's actually a common solution for monetary values -- using whole numbers to represents the total number as cents, instead of using floating point to represent the dollars and cents.

Henry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic