Sum of Doubles that where parsed from a JTable

How to get the sum of Doubles that where parsed from a JTable?

I'm Building a Client/Server Application, and I'm Stuck on a Little issue.

I want get the sum of values of a column in a JTable, this column contains String objects with #,## format, so when I try to parse them into doubles with a loop I get this error:

java.lang.NumberFormatException: For input string: "0,55"

Here is the JTable image:

And here is the code that I tried so far:

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt)    {                                          

    Double summl = 0.0;

    for(int i = 0; i < jTable1.getRowCount(); i++){
        summl=summl+Double.parseDouble(jTable1.getValueAt(i,5).toString());
    }
     System.out.println("summl = "+summl);
   }  

Answers


I think the problem is with the comma in the number. You should try to parse the numbers using NumberFormat class.

E.G.:

public static void main(String[] args) {
        NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH); //Set the proper locale here

        try {
            Double myDouble = (Double)nf.parse("0,55");
            System.out.println(myDouble);
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

Need Your Help

Creating a tree, is div or ul better?

html tree html-lists

I am creating my own tree implementation similar to Dojo or jQuery trees (like a file tree, complete with collapsing/expanding nodes) and I am wondering what advantages/disadvantages coding by ul a...

Can someone define the regular expression to match the following html code

c# javascript .net asp.net regex

I was doing some web scraping and i was looking for some div elements with particular class names and markup.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.