2016-12-27 58 views
-3

我試圖構造一個正則表達式,將剝離出幾個數字的小數點以下字符串的左邊:Rs.6,564.80如何從格式化字符串中提取貨幣金額?

預期結果我在找的是6564。誰能幫幫我嗎?

+0

它只需要是正則表達式嗎?看起來好像這是數字值,沒有它可以更容易做一個零件 –

+1

您使用哪種語言? – TheLostMind

+1

Java還是JavaScript?儘管名稱相似,但這兩個完全不同。 –

回答

-1

試試這個

var a = "6,454.80"; 
var b = a.split('.')[0]; 
b.replace(',',''); 

更多的逗號試試這個

var a = "6,454.80"; 
var b = a.split('.')[0]; 
b.replace(/,/g, "") 
+0

這是我的想法,但不會工作。這會返回'Rs'。注意這個字符串是'Rs.6,...' –

+0

wats這裏錯了嗎? – Sharmila

+0

其實我正在嘗試做一個正則表達式,我要在xml中使用..可以請你幫我在這種情況下.. –

1

試試這個:

var money = "6,454.80"; 
 
var number = Number(money.replace(/[^0-9\.]+/g,"")); 
 

 
console.log(parseInt(number));

1

簡單地分析它爲int。

val = "65,43,214.80"; 
val = replaceAll(val, ',', ''); 


alert(parseInt(val)); 

function replaceAll(str, find, replace) { 
    return str.replace(new RegExp(find, 'g'), replace); 
} 
0

如果您使用的是Java(因爲你已經標記java),您可以使用此:

//Remove all commas 
input = input.replaceAll(",", ""); 
//Extract Rupee part of the amount and skip the Paise part. 
input = input.replaceAll(".*?(\\d+)\\.?(\\d+)?", "$1"); 

我試圖與你的輸入,以及一些其他。似乎爲我工作得很好。

希望這會有所幫助!

+0

我實際上要在xml中使用正則表達式,請您在這種情況下幫助我......並感謝您的回答。 –

+1

爲什麼不編輯問題並添加您正在使用的XML代碼段。那天晚上吸引更好的答案。另外,將XML標籤添加到您的問題。 – anacron