• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Number format Problem - Please advise

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sir,

My input number is looks like 123456789

But using java program, if i read that number, i am getting 123456789.00

how can I avoid that.

Whatever I give the number, java should be display the same.
suppose if i give the input 123456789.00,
it should be displayed the same output.

Is it possible?

Please advise.
[ November 07, 2008: Message edited by: Edward Durai ]
 
Marshal
Posts: 73243
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We would need more details, but you would appear to be putting an int into a double. It would be possible to print a double without .00 if there is no fractional part, but the imprecision of floating-point arithmetic makes that unreliable.
 
Campbell Ritchie
Marshal
Posts: 73243
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try using a BigDecimal to preserve the .00; read the API for BigDecimal and see what it says. Or you could preserve the entry as a String.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic