0

I need re-organize price string first value is 1.778,81 i need last value 2.099,00 the code belove results like 2099,00 i need . before 6th character from last.

$.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' );
}); 
  • If you had googled you would probably have found this: http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript – Michiel May 01 '13 at 08:53

2 Answers2

1

You can try

    var b=KDVsiz;

    var a= b.substring(0,b.length-7) + '.' + b.substring(b.length-7);
    alert(a); 
Sandeep Kumar
  • 783
  • 1
  • 5
  • 13
  • Thanx man i changed the line like this; var KDVsiz = (KDVsiz).substring(0,KDVsiz.length-6) + '.' + (KDVsiz).substring(KDVsiz.length-6); and its ok now. – Emre Gülas May 01 '13 at 10:51
0

See 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, "." );

I think that should work, but I'm way too lazy to test this out, so if someone feels like correcting me I'll edit/remove my answer.

Of course you can inline that:

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

Sandeep's answer is nicer though.

Community
  • 1
  • 1
Jeff
  • 12,555
  • 5
  • 33
  • 60