如何使用java将点(。)替换为逗号(,) [英] How to replace comma (,) with a dot (.) using java
本文介绍了如何使用java将点(。)替换为逗号(,)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串str = 12,12
我想用(逗号)替换。(点)进行十进制数计算,
目前我正在尝试这个:
I am having a String str = 12,12
I want to replace the ,(comma) with .(Dot) for decimal number calculation,
Currently i am trying this :
if( str.indexOf(",") != -1 )
{
str.replaceAll(",","\\.");
}
请帮助
推荐答案
你的问题不在于匹配/替换,但是String是不可变的,你需要分配结果:
Your problem is not with the match / replacement, but that String is immutable, you need to assign the result:
str = str.replaceAll(",","."); // or "\\.", it doesn't matter...
这篇关于如何使用java将点(。)替换为逗号(,)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文