插入字符之前第6个字符从最后jquery
问题描述:
我需要重新组织价格字符串第一个值是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');
});
答
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
答
您可以尝试
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
如果你在GOOGLE上搜索,你可能会发现这一点:http://*.com/questions/2901102/how-to-print-a-number-with-commas- as-thousands-separator-in-javascript – Michiel 2013-05-01 08:53:40