Equals () and indexOf () do not work as I would expect with NumberFormat

I am trying to check if a string (filter) is contained in another string (formattedAmount), that is, it filters the substring formattedAmount.

I couldn't get it to work, so I just changed the code to use "equals ()" instead of "indexOf ()", just for easy testing. The equals method does not work as I would expect.

Here is a dummy script I wrote that replicates what I'm trying to do:

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;


public class utils
{

    public utils()
    {
    }

    public static void main(String[] args) throws Exception 
    {   
        String filter = "333 333,44";
        Number amount = new BigDecimal(333333.44);

        NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRANCE);
        nf.setMinimumFractionDigits(2);

        String formattedAmount = nf.format(amount);

        if (formattedAmount.equals(filter)) 
        {
            System.out.println("Working");
            }
    }
}

Any ideas why it is not included in the If statement?

thank

+5
source share
3 answers

A simple one printlnwill show the truth: the separator of thousands of languages ​​FRANCE IS NOT A SPATIAL CHARACTER :

System.out.println((int)formattedAmount.charAt(3) + " " + (int)filter.charAt(3));

Print

160 32

, .

Try

char s = 160;
String filter = "333" + s + "333,44";
+10

String # . , true true . , : formattedAmount = 33 33 33 c2 a0 33 33 33 2c 34 34 = 33 33 33 20 33 33 33 2c 34 34. 0x20 - , 0xc2a0, , . , false - "3".

+2

nf.format ( 160) 3-. ( 32), .

0

All Articles