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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert constant or field to Float data type for calculation? 1

Status
Not open for further replies.

TroyMcClure

Technical User
Oct 13, 2003
137
US
This is a problem that's I swear I've solved before, but I never can remember what I ended up doing.

I have 2 fields, say [num1] and [num2], which are stored in the db as long integer.

In a report's ControlSource, I try to avg as:
Code:
=Csng(Csng([num1])\Csng([num2]))

This ALWAYS results in a non-float result (the field is formatted as standard, 1 decimal). Even if I take the actual values in the Debug window:
Code:
?format(csng(csng(58)\csng(9)),"0.00")
6.00
or 
?format(csng(58!\9!),"0.00")
6.00

How do I get it to cast correctly? I've tried all sorts of combinations of using type declaration, explicit conversions, Format(), etc, but the above numbers ALWAYS return 6, in some format or another, not 6.444444....
--T
 
You are doing integer division by using the backslash character (\). Floating-point division uses the forward slash (/).
 
Thanks, that did it! It's one of those things I've somehow worked around but I'd never known till now.
--T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top