2013-05-01 45 views
0

我需要重新組織價格字符串第一個值是1.778,81我需要最後值2.099,00代碼belove結果像我需要的2099,00。在從最後的第6個字符之前。插入字符之前第6個字符從最後jquery

$.each($(".indirimsiz_urun_fiyati span"), function(index) { 
    var KDVsiz = $(this).html().replace(' TL + KDV', ''); 
    var KDVsiz = (KDVsiz).replace(/\./g,""); 
    var KDVsiz = (KDVsiz).replace(/,/g,"."); 
    var KDVsiz = (parseFloat(KDVsiz,10) * 1.18).toFixed(2); 
    var KDVsiz = (KDVsiz).replace(/\./g,","); 
    $(this).text(KDVsiz + ' TL'); 
}); 
+0

如果你在GOOGLE上搜索,你可能會發現這一點:http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas- as-thousands-separator-in-javascript – Michiel 2013-05-01 08:53:40

回答

0

the answer to this question

String.prototype.splice = function(idx, rem, s) { 
    return (this.slice(0,idx) + s + this.slice(idx + Math.abs(rem))); 
}; 
KDVsiz = KDVsiz.splice(KDVsiz.length - 6, 0, "."); 

我認爲應該工作,但是我太懶惰測試了這一點,所以如果有人感覺就像糾正我,我會編輯/刪除我的答案。

當然你也可以內聯:

KDVsiz = KDVsiz.slice(0,KDVsiz.length - 6) + "." + KDVsiz.slice(KDVsiz.length - 6); 

Sandeep的答案是更好不過。

+0

BULLSEYE jeff thank you! – 2013-05-01 10:54:06

1

您可以嘗試

var b=KDVsiz; 

    var a= b.substring(0,b.length-7) + '.' + b.substring(b.length-7); 
    alert(a); 
+0

Thanx男人,我改變了這樣的路線; var KDVsiz =(KDVsiz).substring(0,KDVsiz.length-6)+'。' +(KDVsiz).substring(KDVsiz.length-6); 現在就好了。 – 2013-05-01 10:51:40

相關問題