Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

java - Removing Dollar and comma from string

How can we remove dollar sign ($) and all comma(,) from same string? Would it be better to avoid regex?

String liveprice = "$123,456.78";
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

do like this

NumberFormat format = NumberFormat.getCurrencyInstance();
Number number = format.parse("$123,456.78");
System.out.println(number.toString());

output

123456.78

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...