Library code snippets
Format field to currency
Looking to format a field to US dollar currency style? This function will round your value to the nearest tenth position, and add a dollar sign.
The following code is a JavaScript function. Simply pass your numeric value to this function and it will format it for you:
<script language="javascript">
function currency( num )
{
var prefix = "$";
var suffix = "";
if ( num < 0 )
{
prefix = "($";
suffix = ")";
num = - num;
}
var temp = Math.round( num * 100.0 ); // convert to pennies!
if ( temp < 10 ) return prefix + "0.0" + temp + suffix;
if ( temp < 100 ) return prefix + "0." + temp + suffix;
temp = prefix + temp; // convert to string!
return temp.substring(0,temp.length-2) + "." + temp.substring(temp.length-2) + suffix;
}
</script>
Related articles
Related discussion
-
Animation Library Javascript - Computer Animation How To
by MarkHewitt (0 replies)
-
Buy cheap Xanax overnight. Cheap Xanax. Overnight delivery of Xanax in US no prescription needed. Cheapest Xanax.
by asleymar (0 replies)
-
Buy Soma online without a prescription. Soma drug no prescription. How to get Soma prescription. Soma cod accepted.
by asleymar (0 replies)
-
Cheap online order Fioricet. Cheap discount Fioricet. Offshore Fioricet online. How to buy Fioricet online without a prescription.
by asleymar (0 replies)
-
Buy Ambien no visa without prescription. Not expensive Ambien prescriptions. Ambien no rx. Cod delivery Ambien.
by asleymar (0 replies)
Related podcasts
-
jQuery in ASP.NET
In this episode Chris Brandsma, Rick Strahl, Dave Ward, Bertrand Le Roy, Scott Koon, and Steven Harman discuss Microsoft's jQuery in ASP.NET announcement.This episode of the Alt.NET Podcast is brought to you by LLBLGen Pro, the most mature O/R mapper and code generator out there.Are you loo...
Events coming up
-
Feb
25
Mitcho's talk on Ubiquity and/or JetPack
Cambridge, United States
Our February 2010 JavaScript Meetup will be held on Thursday, February 25th at Microsoft Research Center located at One Memorial Drive in Cambridge. When you arrive security will direct you to the correct floor. There is also parking available at a cheap evening rate in the building. Parking is also free on the street in front of the building at 6 PM.At 6:30 PM our fellow member Mitcho (mitcho.com) will share his knowledge of Ubiquity and/or JetPack. I hear he is an awesome presenter.
This thread is for discussions of Format field to currency.