|
-
Formatting Currency with Commas
I was able to find the following script to format currency with commas but for some reason it keeps dropping the trailing zero.
For example, if the amount is $11,750.10 it formats it as "$11,750.1".
I've played around with this for the last day or so without any luck. I need some Java expertise as I'm a VB person.
===============================
function formatCurrency(n,d) // n = number, d = delimeter
{
// round to 2 decimals if cents present
n = (Math.round(n * 100) / 100).toString().split('.');
var
myNum = n[0].toString(),
fmat = new Array(),
len = myNum.length,
i = 1, deci = (d == '.') ? ',' : '.';
for(i; i < len + 1; i++) fmat[i] = myNum.charAt(i-1);
fmat = fmat.reverse();
for(i = 1; i < len; i++)
{
if(i % 3 == 0) {
fmat[i] += d;
}
}
var val = fmat.reverse().join('') +
( n[1] == null ? deci + '00' :
(deci + n[1])
);
}
return val;
}=======================
Thanks in advance!
Kevin
Similar Threads
-
By ortizsr in forum VB Classic
Replies: 11
Last Post: 06-23-2005, 07:56 AM
-
Replies: 1
Last Post: 10-31-2002, 09:41 PM
-
By Magic in forum VB Classic
Replies: 1
Last Post: 03-22-2002, 07:23 PM
-
By Simon Jones in forum Java
Replies: 0
Last Post: 10-17-2001, 05:44 AM
-
Replies: 4
Last Post: 07-18-2000, 04:21 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks