The getPositivePrefix () method returns a string with a currency symbol and a space character. They do this in order to have a currency symbol and value shared.
Don't you need a space character? You can do two things:
Solution 1
String symbol = df.getDecimalFormatSymbols().getCurrencySymbol(); System.out.println("\n"+"currencySymbol:"+ symbol + "500\tlength:"+symbol.length());
Output:
currencySymbol:€500 length:1
Decision 2
Add a escape escape sequence: '\ b', this will remove space during printing. But the size of the string length will remain when the length () method is called
String symbol = df.getPositivePrefix(); System.out.println("\n"+"currencySymbol:" + symbol +"\b500\tlength:"+symbol.length());
Output:
currencySymbol:€500 length:2
source share