0

i have got little problem. I scanned numbers from .csv file into 2d array of strings. Now i need to parse it into 2d array of Number type. Not int or double. The error says:

Required type: com.sun.org.apache.xpath.internal.operations.Number Provided: java.lang.Number

Can you please take a look ?

 for (int a = 0; a < rows; a++) {
        for (int b = 0; b < cols; b++) {
            parsedContent[a][b] = NumberFormat.getInstance().parse(arrayOfStrings[a][b]);   
        }
 }

1 Answer 1

1

I have a small sample programm for you:

public static void main(String[] args) throws Exception{

        int rows = 2;
        int cols = 3;

        String[][] arrayOfStrings = {{"1.1","2.222222222","3.333"},{"4.44","5555","666"}};

        Number[][] parsedContent = new Number[rows][cols];

        NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);

        for (int a = 0; a < rows; a++) {
            for (int b = 0; b < cols; b++) {
                parsedContent[a][b] = numberFormat.parse(arrayOfStrings[a][b]);
                System.out.println(parsedContent[a][b]);
            }
        }
}

Outout:

1.1
2.222222222
3.333
4.44
5555
666

Is that what you mean? Otherwise I need more code details and some sample Strings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.