简体   繁体   中英

How to set a double format by locale

I those input strings:

 10000,20
 4000,10
 5,400.20

I am trying to format them with locale:

nf = NumberFormat.getInstance(Locale.FRANCE);
double newLoc = nf.parse(split[5]).doubleValue();

And also like this:

   nf = NumberFormat.getInstance(Locale.ENGLISH);
    double newLoc = nf.parse(split[5]).doubleValue();

Result is: for Locale.FRANCE

5400.2 
4000.0 
10000.0

For Locale.ENGLISH

4000.0
10000.0
5400.0

But what in need is smth like this: for Locale.France

10 000,2 
4 000,1
5 400,2

And Locale.English

10,000.2
4,000.1
5,400.2

You can't present double or float in format 10,000.2 or 10 000,2 , this is String format. You can use for example String.format() method to do it. More info about this read here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM