TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jes Sie
743
1.2k
284.7k
Format Currency with comma and decimal
Jun 25 2020 1:31 AM
Hello everyone, I need your assistance. I need to format a numeric value to contain comma and decimal. I found this jquery (below) but it does not have a decimal. Can someone help me with how to add a decimal place? thank you.
function
FormatCurrency(ctrl) {
//Check if arrow keys are pressed - we want to allow navigation around textbox using arrow keys
if
(event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) {
return
;
}
var
val = ctrl.value;
val = val.replace(/,/g,
""
)
ctrl.value =
""
;
val +=
''
;
x = val.split(
'.'
);
x1 = x[0];
x2 = x.length > 1 ?
'.'
+ x[1] :
''
;
var
rgx = /(\d+)(\d{3})/;
while
(rgx.test(x1)) {
x1 = x1.replace(rgx,
'$1'
+
','
+
'$2'
);
}
ctrl.value = x1 + x2;
}
function
CheckNumeric() {
return
event.keyCode >= 48 && event.keyCode <= 57;
}
Reply
Answers (
1
)
How to disable right click on object tag?
How to submit two url in single click ?