[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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.
0
smetterd
Asked:
smetterd
  • 4
  • 3
  • 2
2 Solutions
 
smetterdAuthor Commented:
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
 
jitgangulyCommented:
What if you use cdbl function ? like

formatnumber(cdbl(z1) + cdbl(z2))
0
 
John_LennonCommented:
try
Res = 0.0 + z1 + z2
response.write res
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
smetterdAuthor Commented:
both work perfectly. THANKS!!
0
 
jitgangulyCommented:
I deserve full points here, why split ?
0
 
John_LennonCommented:
glad to help
0
 
smetterdAuthor Commented:
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
 
jitgangulyCommented:
Post a 200 pts Q for me
0
 
smetterdAuthor Commented:
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now