Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number Conversion Problem

 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All.

I am using JTable having values in column 3.
I am getting values from it using jTable.getValueAt(1,1).toString;
Then i use Double/Float/Integer/Long etc to convert data.
My data having values 999,999,999,999.99
Problem is that thru any of above option i get 9.9999999999999
in sum of different values. My jTable contents number of values positive and negative.

Can anyone help me where i m wrong or is there any other way to solve my this problem.

I am using the same below method except Double.parseDouble(), Integer.parseInt() etc etc

 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that the parse methods of Double, etc. all assume the String has no formatting elements excpet . Since yours does, you should use DecimalFormat to parse String values with , seperators.
http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic