简体   繁体   中英

How to parse String with multiple delimeters into long

I need to parse String value into Long . Problem is, that value is separated by dots, so they are once groupingSeparator and once decimalSeparator. So 50.000 should be parsed to 50 , but 5.000.000 need to be parsed to 5000 . I've tried with DecimalFormat , but i cannot set it properly, and ended up with parsing 5.000.000 into 5 since dots were treated as decimalSeparator always.

String number = "5.000.000";
        String substring = number.substring(0, number.lastIndexOf("."));
        System.out.println(Long.parseLong(substring.replaceAll("\\.","")));

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