Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add decimal to last two numbers in numeric string

I have the following numeric string where I need to add a decimal to the last two numbers.

So

300000

Becomes

3000.00

Can someone please help me out here, which regex code should I use for this? Or should I not use regex at all for this.

Thanks

like image 267
user2028856 Avatar asked Feb 11 '23 13:02

user2028856


1 Answers

var str="300000";

var resStr=str.substring(0,str.length-2)+"."+str.substring(str.length-2);

document.write(resStr);
like image 189
Ramkumar Avatar answered Feb 13 '23 02:02

Ramkumar