Solved

convert javascript print function to USD currency

Posted on 2010-08-18
3
279 Views
Last Modified: 2012-05-10
I am using the code below to display a $ amount on my site based on a shopping cart script...It works fine but prints out as 10.00 or 11.55 or 12.04 I want to convert it to USD such as $12.05 or $11.00..I know I can simply add a $ in front of it, but I may need to use different currency types..Thanks
<SCRIPT language="JavaScript">
Print_total();
</script>

Open in new window

0
Comment
Question by:brad0525
  • 2
3 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33464008
Please post the script that actually does the Print_total()
0
 

Author Comment

by:brad0525
ID: 33465168
Here you go..thanks
function Print_total( ) {

var strOutput = ""; //String to be written to page

var strTotal = ""; //Total cost formatted as money

var fTotal = 0;

var iNumberOrdered = 0; //Number of products ordered





iNumberOrdered = GetCookie("NumberOrdered");

if ( iNumberOrdered == null )

iNumberOrdered = 0;





for ( i = 1; i <= iNumberOrdered; i++ ) {



NewOrder = "Order." + i;

database = "";

database = GetCookie(NewOrder);



Token0 = database.indexOf("|", 0);

Token1 = database.indexOf("|", Token0+1);

Token2 = database.indexOf("|", Token1+1);

Token3 = database.indexOf("|", Token2+1);

Token4 = database.indexOf("|", Token3+1);



fields = new Array;

fields[0] = database.substring( 0, Token0 ); // Product ID

fields[1] = database.substring( Token0+1, Token1 ); // Quantity

fields[2] = database.substring( Token1+1, Token2 ); // Price

fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description

fields[4] = database.substring( Token3+1, Token4 ); // Weight

fields[5] = database.substring( Token4+1, database.length ); //Additional Information



fTotal += (parseInt(fields[1]) * parseFloat(fields[2]) );



}



strTotal = moneyFormat(fTotal);

strOutput+=strTotal;

document.write(strOutput);



}

Open in new window

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 33465292
strOutput+="$"+strTotal;
document.write(strOutput);


or


function Print_total(currencyChar) {

.
.
strOutput+=currencyChar+strTotal;
document.write(strOutput);


and have

<SCRIPT language="JavaScript">
Print_total("$");
</script>



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now