/    Sign up×
Community /Pin to ProfileBookmark

format number in textbox … any help?

hi

i have this jquery function

$(function() {

$(“#Text3”).change(function() {
var add = 0;
$(“.amt”).each(function() {
add += Number($(this).val());
});
$(“#total”).text(“Sum of all textboxes is : ” + add);

});
});

<input id=”Text1″ class=”amt” type=”text” /><br />
<input id=”Text2″ class=”amt” type=”text” /><br />
<input id=”Text3″ class=”amt” type=”text” /><br />

<p id=”total”>

From this function i will display the sum of this 3 boxes.

What is need is to format the result.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@pwinfreyApr 27.2011 — How are you wanting to format the result?
Copy linkTweet thisAlerts:
@adriana_popescuauthorApr 27.2011 — I need to have some total price in UK Pounds.
Copy linkTweet thisAlerts:
@adriana_popescuauthorApr 27.2011 — i have the solution now ....

i use this function

function number_format (number, decimals, dec_point, thousands_sep) {

number = (number + '').replace(/[^0-9+-Ee.]/g, '');
var n = !isFinite(+number) ? 0 : +number,
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
s = '',
toFixedFix = function (n, prec) {
var k = Math.pow(10, prec); return '' + Math.round(n * k) / k;
};
// Fix for IE parseFloat(0.55).toFixed(0) = 0;
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
if (s[0].length > 3) { s[0] = s[0].replace(/B(?=(?:d{3})+(?!d))/g, sep);
}
if ((s[1] || '').length < prec) {
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1).join('0'); }
return s.join(dec);

}
×

Success!

Help @adriana_popescu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...