I face the below problem in java 8
import java.util.*;
import java.text.*;
import java.lang.*;
class NumberTest5 {
public static void main(String[] args) {
Locale loc = new Locale("sr","ME");
DecimalFormat df = (DecimalFormat)NumberFormat.getCurrencyInstance(loc);
System.out.println("\n"+"currencySymbol:"+df.getPositivePrefix()+"\tlength:"+df.getPositivePrefix().length());
//here the above result is currencySymbol: €+(non breakable space char)
//length:2
}
}
the real question is why there is an extra character appended to the currency symbol ..?
why the above program behaves in this way ...?.
what is the problem in it & how to rectify it ..?
Thanks
It's not invalid.
The following
Locale loc = new Locale("sr","ME");
represents the Locale
for Serbian in Montenegro. I can't find the equivalent for Java, but here's a description of this locale for glibc. Under Currency, you'll notice Space separation between symbol and value
is set to 1
, indicating that
a space separates the symbol from the value
Therefore, if you formatted a value, for example
System.out.println(df.format(123.45));
you'd get
€ 123,45
with a space between the currency symbol at the value.
That's what the positive previx represents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With