Latest Snippets

Postback - showModalDialog

You'll notice if you do a postback/submit within a dialog window in IE, it posts...

General snippet posted by Christoff Truter on 2009-09-23 07:19:57
View Snippet

 

Set Maximum Request Size

In your web.config, find the system.web node and add the httpRuntime child node,...

ASP.net snippet posted by Christoff Truter on 2009-07-29 11:55:22
View Snippet

 

Force site to run in IE7 Compatibility mode

Recently we developed an intranet application simply using all the microsoft com...

General snippet posted by Christoff Truter on 2009-07-22 10:00:19
View Snippet

 

FileSystemWatcher example

An example of how to monitor the filesystem using the filesytemwatcher class in ...

C# snippet posted by Christoff Truter on 2009-06-27 22:08:12
View Snippet

 

Format Currency

Format a string into a currency format, similar to the FormatCurrency function i...

Javascript snippet posted by www.sonofsofaman.com on 2009-06-12 09:52:50
View Snippet

 

MD5 hash

The following snippet demonstrates how to create a MD5 hash using SQL 2005...

MSSQL snippet posted by Christoff Truter on 2009-06-11 10:01:37
View Snippet

 

Register Globals off

If you don't have access to your php.ini or the ability to set register_globals ...

PHP snippet posted by Christoff Truter on 2009-06-09 11:47:26
View Snippet

 

Table Variables

SQL 2000 introduced an alternative to temporary tables called table variables....

MSSQL snippet posted by Christoff Truter on 2009-06-08 15:59:55
View Snippet

 

MD5 hash

Calculate the MD5 hash of a given string...

C# snippet posted by Christoff Truter on 2009-06-02 14:08:47
View Snippet

 

Row Number

How to number rows of a query using mysql...

MySQL snippet posted by Christoff Truter on 2009-05-22 14:36:53
View Snippet

 

Snippets

Format Currency

Format a string into a currency format, similar to the FormatCurrency function in VBScript

Source:
http://www.sonofsofaman.com/hobbies/code/js/formatcurrency.asp

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);
 
	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}
 


posted by www.sonofsofaman.com on 2009-06-12 09:52:50

 

Comments


Write a comment

* *
*

* Required fields

Latest Javascript Snippets

Format Currency

Format a string into a currency format, similar to the FormatCurrency function i...

posted by www.sonofsofaman.com on 2009-06-12 09:52:50
View Snippet

 

Shift option up/down in dropdown/listbox

The following snippet will shift a selected option up/down a defined dropdown/li...

posted by Christoff Truter on 2009-05-22 09:23:58
View Snippet

 

Clone Objects

Functionality to clone objects in javascript...

posted by Christoff Truter on 2009-05-22 08:56:34
View Snippet

 

Modal-style pops in Javascript and CSS

a simple example of how to create a css/javascript based modal popup. Like se...

posted by Christoff Truter on 2009-05-14 16:08:20
View Snippet

 

Numeric Textbox

The following snippet restricts a textbox to only accept numerical values. Us...

posted by Christoff Truter on 2009-05-07 12:14:49
View Snippet

 

Toggle visibility of an html element

Simply send the id of an element to this function, and it will toggle its visibi...

posted by Christoff Truter on 2009-05-07 11:06:20
View Snippet

 

Add url to favorites

How to add an url to browser favorites. This example works for IE/FF eg: ...

posted by Christoff Truter on 2009-05-07 11:04:51
View Snippet

 

Attach Event

Here is a simple snippet on how to alias the addEventListener function to the at...

posted by Christoff Truter on 2009-04-30 14:41:35
View Snippet

 

Move items from one dropdown to another

Move one(or multiple hold ctrl key in) dropdown items from one dropdown box to a...

posted by Christoff Truter on 2009-02-16 12:32:16
View Snippet

 

Tab key in a textarea

This script enables a textarea to be able to accept tab key strokes. Simply a...

posted by Christoff Truter on 2009-02-14 14:00:43
View Snippet