Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple calculation with currency

Status
Not open for further replies.

andyvb

Programmer
Jan 16, 2002
3
GB
Hi there,

Please can someone advise, I'm trying to get the sum of two variables (that as taken from a select statement in SQL). The result of the values are are in currency format i.e.£XXX.XX but for some reason i keep on being returned the same figures concated e.g £10.50£15.30 and not £25.80. The code i am using is below.

<%
Dim total

Dim one
One = strone

Dim two
two = strtwo

total = one + two %>

<P><%response.write(total)%>

Although i have noticed that when i hard code in a value, it returns the sum calculation i'm trying to acheive.

<%
Dim total

Dim one
One = strone

Dim two
two = 15.30

total = one + two %>

<P><%response.write(total)%>

Many thanks in advance, Andy
 
I would suggest that you leave the amounts as numbers and then format the total.

e.g.

Dim total

Dim one
One = numone '(i.e. 10.5)

Dim two
two = numtwo '(i.e. 15.3)

total = one + two %> '(Total no contains 25.8)

<P><%response.write FormatCurrency(total)%> '(Output will be £25.80)



Mise Le Meas,

Mighty :)
 
Thanks for the reply, i gave this a go and now i get the error below:

Microsoft VBScript runtime error '800a000d'

Type mismatch

This error goes away when i specify a format for my variable! e.g. FormatCurrency or FormatNumber, but then i get the concat again!?

Any suggestions?

Thanks
Andy
 
CAn you please post all your code - showing where you get the information from the DB. What format are the currency amounts in Access - are they numeric or string..

It seems in your first example like the values are treated as strings. Try getting rid of the pound sign by doing something like:

<%
Dim total

Dim one
One = CDbl(Mid(strone, 2))

Dim two
two = CDbl(Mid(strtwo, 2))

total = one + two %>

<P><%response.write FormatCurrency(total)%>

Mise Le Meas,

Mighty :)
 
Hi there

This is all my coding!, the rs should set the variables as &quot;988.5&quot; as this is the result of the SQL query.

my script:

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<HTML>

<P><%=rs2(strpn)%>

<P>booking for the weeks beginning...

<%
If request.form(&quot;20-JAN-02&quot;)=&quot;on&quot; then

strSQL3 = &quot;select * from cavailability where from_date = '20-JAN-02'&quot;


Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open &quot;dsn=Oracle;uid=hh;pwd=hh&quot;
set rs3=conn.execute(strSQL3)

Dim strone
strone = rs3(strpb)


response.write &quot;<br>20-JAN-02 costing: &quot;

response.write FormatCurrency(rs3(strpb), 2)

else

strone = 0


end if

If request.form(&quot;27-JAN-02&quot;)=&quot;on&quot; then

strSQL4 = &quot;select * from cavailability where from_date = '27-JAN-02'&quot;


Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open &quot;dsn=Oracle;uid=hh;pwd=hh&quot;
set rs4=conn.execute(strSQL4)

Dim strtwo
strtwo = rs4(strpb)


response.write &quot;<br>27-JAN-02 costing: &quot;

response.write FormatCurrency(rs4(strpb), 2)

else

strtwo = 0


end if

%>

<%
Dim total
Dim one
One = strone
Dim two
two = strtwo

total = one + two %>

<P><%response.write FormatCurrency(total)%>

</BODY>
</HTML>


I gave your last suggestion a go and received the error:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CDbl'

Please let me know if you come up with anything!?
Thanks Andy



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top