Solved

# Cast value as number with 2 decimal places, then be able to average

Posted on 2006-05-02
235 Views
I am pulling values from a db like this

z0=formatnumber((int(rstemp.Fields.Item("q1").Value) + int(rstemp.Fields.Item("q2").Value) + int(rstemp.Fields.Item("q3").Value)  + int(rstemp.Fields.Item("q4").Value)  + int(rstemp.Fields.Item("q5").Value)  + int(rstemp.Fields.Item("q6").Value)  + int(rstemp.Fields.Item("q7").Value)  + int(rstemp.Fields.Item("q8").Value)  + int(rstemp.Fields.Item("q9").Value)) /9)

z0 then returns a value that I like such as 2.74

z1=formatnumber((int(rstemp2.Fields.Item("q1").Value) + int(rstemp2.Fields.Item("q2").Value) + int(rstemp2.Fields.Item("q3").Value)  + int(rstemp2.Fields.Item("q4").Value)) /9)

z1 then returns a value that I like such as 3.43

I need to then add them together to get 6.17
Trouble is, of course, that if I do a

response.write z1 + z2

it simply concatenates the text values and returns 2.743.43 - that's not going to work ;-)

If I do a

response.write  int(z1) + int(z2)

it returns 5

I am confused!

I need to find out how to make it return 6.17 so I can divide it by 2 and get an average.
0
Question by:smetterd

LVL 2

Author Comment

I tried this

formatnumber(int(z1) + int(z2))

And that returns 5.00

It stripping the value of the two decimal places but I need it to stay!
0

LVL 20

Accepted Solution

What if you use cdbl function ? like

formatnumber(cdbl(z1) + cdbl(z2))
0

LVL 6

Assisted Solution

try
Res = 0.0 + z1 + z2
response.write res
0

LVL 2

Author Comment

both work perfectly. THANKS!!
0

LVL 20

Expert Comment

I deserve full points here, why split ?
0

LVL 6

Expert Comment

0

LVL 2

Author Comment

His worked perfectly also, and it's actually less code to write.

The <b>last</b> thing that i want to do is upset someone who helps me... so how can I go about getting you more points?
0

LVL 20

Expert Comment

Post a 200 pts Q for me
0

LVL 2

Author Comment

0

## Featured Post

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
how to add IIS SMTP to handle application/Scanner relays into office 365.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…