简体   繁体   English

如何将具有多个分隔符的String解析为long

[英]How to parse String with multiple delimeters into long

I need to parse String value into Long . 我需要将String值解析为Long Problem is, that value is separated by dots, so they are once groupingSeparator and once decimalSeparator. 问题是,该值由点分隔,因此它们一次是groupingSeparator,一次是小数。 So 50.000 should be parsed to 50 , but 5.000.000 need to be parsed to 5000 . 因此,应将50.000解析为50 ,但是需要将5.000.000解析为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. 我试着DecimalFormat ,但我不能将其设置正确,并结束了与解析5.000.0005 ,因为点分别为decimalSeparator总是处理。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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