Login    Forum    Search    FAQ   Blog

Board index » Client-Side Development » Javascript




 Page 1 of 1 [ 2 posts ] 



Author Message
 Post subject: formating inn js
 Post Posted: Thu Aug 27, 2009 9:00 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
i am having 3 Typs of no. Formats..Like 1234,1234.00,(1234) ..

Generally i am having 3 TextBoxes..

1st TextBox have 1234

2nd one-> 1234.00

3 rd one -> (1234)

when i am entering any type od values in these TextBoxes i need according to the TextBoxes formattas..

Suppose when i type in first textbox 1234.5 i want to show only 1234..


could u ppl please help me?

Thanks


Top 
 Post subject: Re: formating inn js
 Post Posted: Thu Aug 27, 2009 9:01 am 
Offline

Joined: Sat Feb 21, 2009 2:15 pm
Posts: 62
Hi,

Code:
function format_number(pnumber,decimals){
if (isNaN(pnumber)) { return 0};
if (pnumber=='') { return 0};
var snum = new String(pnumber);
var sec = snum.split('.');
var whole = parseFloat(sec[0]);
var result = '';
if(sec.length > 1){
var dec = new String(sec[1]);
dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
var dot = dec.indexOf('.');
if(dot == -1){
dec += '.';
dot = dec.indexOf('.');
}
while(dec.length <= dot + decimals) { dec += '0'; }
result = dec;
} else{
var dot;
var dec = new String(whole);
dec += '.';
dot = dec.indexOf('.');
while(dec.length <= dot + decimals) { dec += '0'; }
result = dec;
}
return result;
}

_________________
The average woman would rather have beauty than brains, because the average man can see better than he can think.


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 2 posts ] 




Board index » Client-Side Development » Javascript


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron