我有一個字符串。如何將此String(包含字符串和整數)轉換爲實際的數字? (Java)
String value = "The value of this product: 13,45 USD";
我想這是一個雙重這應該是這樣的:
double actualprice=13,45;
或者我應該使用浮動,雙沒用嗎?對不起,我不是專家。
那麼我怎樣才能將這個字符串轉換爲數字?
哦,我差點忘了,我有一個代碼,它使它成爲「13,45」,但它仍然是一個字符串。
String price = "The price is: 13.45";
String s = price;
for(int b=0;b<s.length();b++){
if(s.charAt(b)=='.') {
System.out.print(",");
}
if(Character.isDigit(s.charAt(b))) {
System.out.print(s.charAt(b)+"");
}
}
您的雲嘗試使用一些正則表達式,並用「」替換所有的數字值。那麼你只需要調用Double的解析方法:) – damus4
如何將商店'13,45'存儲在'double'中?順便說一句 – Blip
,因爲逗號 – maxgraham