Fixing numbers ...

1. Member
Join Date
Dec 1969
Posts
47

## Fixing numbers ...

Hi all,<BR><BR>Building a shopping system from scratch I came across something I can&#039;t seem to get a grip on.<BR><BR>After setting up the shopscript it turned the cents into 00 !!! ( see http://www.empc.nl Hardware Bestel(Order))<BR><BR>Using following Order script :<BR>function order(a,p){ if (DD(a)) { if (Cl("h")) h=Cl("h")+";1"; else h=1+";"; if (Cl("a")) a=Cl("a")+";"+a; else a=a+";"; if (Cl("t")) t=Cl("t")+";"+p; else t=p+";"; C2("h", h, verloop); C2("a", a, verloop); C2("t", t, verloop)} ww=window.open("shop.html","ww","width=480,height= 380,scrollbars=1,toolbar=0,directories=0,resizable =0,dependent=0,titlebar=0,personalbar=0,menubar=0, status=0,location=0")}<BR><BR>I tried a fixnum function wich I had laying around but it didn&#039;t seem to work :<BR>function Fix(val){return parseFloat(val.replace(".",","));}<BR><BR>Is there anybody out there who can help ??<BR><BR>Any hints / tips will be greatly appreciated.<BR><BR>Many thanx in advance<BR><BR>Orb_X<BR>Orb_X@hotmail.com

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Fixing numbers ...

I do not understand, AT ALL, what your "order" function is supposed to be doing or how it is at all related to your question about formatting currency.<BR><BR>So I am going to ignore it and show you how I format currency (adapted to use European instead of USA notation):<BR><BR>function formatCurrency( num )<BR>{<BR>&nbsp; &nbsp; var temp = &#039;&#039; + Math.round( num * 100 ); // for 2 decimal places!<BR>&nbsp; &nbsp; if ( temp.length == 1 ) return "0,0" + temp;<BR>&nbsp; &nbsp; if ( temp.length == 2 ) return "0," + temp;<BR>&nbsp; &nbsp; return temp.substr(0,temp.length-2) + "," + temp.substr(temp.length-2);<BR>}<BR><BR>That assumes you need 2 decimal places. If you need a different number, just ask.<BR><BR>Also, that doesn&#039;t work, as is, for negative numbers. Ask if you need to handle negative currency, as well.<BR><BR>

3. Member
Join Date
Dec 1969
Posts
47

## Thnx Mr. Wilkinson :-) <eom>

.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•