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!

Problem performing divide calculations in a view?

Status
Not open for further replies.

Rahel

Programmer
Feb 16, 2000
30
GB
I am having problem trying to do calculations in a view.<br>I am trying to divide the values in one column by a value in another column. <br><br>I have no problem adding, subtracting or multiplying columns and receiving the correct result however, when trying to perform a divide calculation I get only ones and zeros instead of the correct answer.<br><br>Has anyone encountered this problem trying to do a divide calculation in a view? or knows of a fix for this problem.<br><br>I need to calculate some percentages and this problem has baffled me.<br><br>Anyone one out there who can help or suggest a course of action to follow.
 
I would guess it might be something to do with using integer and them being truncated.<br>i.e.<br>select (1/4),(2/4),(3/4),(4/4)<br><br>outputs: 0 0 0 1<br>whereas<br><br>select (1.0/4.0),(2.0/4.0),(3.0/4.0),(4.0/4.0)<br><br>outputs 0.25 0.5 0.75 1.0
 
ColinM is probably right.&nbsp;&nbsp;To avoid the problem, CAST one of the operands as a decimal or float prior to the division.&nbsp;&nbsp;The result will then assume that same precision. <p>Malcolm Wynden<br><a href=mailto:wynden@island.dot.net>wynden@island.dot.net</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top