473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Display textbox value as currency ($999,999,999) format

1
I have a text box in which user enters value for some money. I want to display the money in currency format ie,$999,999,999 format.
Ex: If somebody enters 123456 then it on blur should display $123,456.

Can anyone please help me in this?

Thanks in advance.
Aug 29 '07 #1
1 17350
nedu
65
Hi Frnd,

You shall use the following code
[html]
<SCRIPT LANGUAGE="JavaScript">

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
// End -->
</script>

<html>
<head></head>
<body>
<input type=text onBlur="this.value=formatCurrency(this.value)">
<input type=text>
</body>
</html>[/html]
Regards,
Nedu. M
Aug 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: I_have_nothing | last post by:
Hi! Is there any easy way to printf an integer in a way like 1,234,567? I know "%d" can be usd to print it as 1234567. Any type field in format specification can do that? Or any easy way to do...
1
by: nic | last post by:
Hi, I have a textbox value that I need to force (and format) to be a numeric value. For example, I want to allow a user to type 1000 or 1,000 or 1,000,000 but not something that is not numberic....
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
1
by: doll | last post by:
Hi All, Greetings. I am creating a form in which i have text box and listbox together. While entering any text values (such as a,b,c) in the textbox it should display the listbox below which...
7
by: TechnoAtif | last post by:
Hi..There is again a similar problem..Now i;ve got the option values of list?menu box to show the textbox. If the option value of list is yes then the textbox is to be displayed . Can anyone...
0
by: hemadribabu | last post by:
hi , i have a textbox in my asp.net page, in this textbox some integer value will be displayed , Now i have to make that displayed integer value to be displayed in INR format , plstell me how to...
10
by: lakki63 | last post by:
hi all.. I m new to html....In my html page i place one multiline textbox...My query is when i enter data into textbox and click submit button..i have to display dat message in below to the...
2
by: digituf | last post by:
may i know if in php i can assign the textbox value from the user input as variables and then display the result of in the same page. assume, user insert the checkin and checkout date, then it...
1
by: nawedita | last post by:
Hi I am facing a problem with my code .... this is what I am doing ... I am running this dropdown in while loop...and i want when i select Cheque then display textbox otherwise textbox not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.