Link to home
Start Free TrialLog in
Avatar of smetterd
smetterdFlag for United States of America

asked on

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

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.
Avatar of smetterd
smetterd
Flag of United States of America image

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of jitganguly
jitganguly

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
both work perfectly. THANKS!!
Avatar of jitganguly
jitganguly

I deserve full points here, why split ?
glad to help
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?
Post a 200 pts Q for me