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

Rounded result isn't the desired result. How to 'unround'? 1

Status
Not open for further replies.

RCCRookie

Technical User
Jul 3, 2007
29
0
0
US
My thanks to IanWaterman for posting the following formula which seems to have solved the problem I've been struggling with. Of course, no sooner, is one problem solved and another comes along to fill the void! The result is rounded and I prefer to display two digits to the right of the decimal. What I'm getting is 3 (hours) and what I want is 3.75 (hours). I'd also appreciate if someone could explain what exactly the formula is doing and if in fact this is a workable solution to calculating the averagehours between a start date and an end date (@Preventive Hours-- datediff('h',{PREVENTIVE_MNT_V.START_DATE},{PREVENTIVE_MNT_V.END_DATE})). I'm attempting to learn how to utilize formulas in Crystal (other than copy and paste) and I'm trying to understand the why's and whatfor's. Crystal XI, SQL 2000 DB

Thanks!

whileprintingrecords;
local numbervar avtime:= average({@Preventive Hours},{EQUIPMENT_MNT_V.EQUIPMENT_ID});

local numbervar hour:= int(avtime/3600);

local numbervar min:= int((remainder(avtime,3600))/60);

local numbervar sec:= remainder(remainder(avtime,3600),60);
 
First change {@PreventiveHours} to:

datediff('s',{PREVENTIVE_MNT_V.START_DATE},{PREVENTIVE_MNT_V.END_DATE}))

Then change your average formula to:

whileprintingrecords;
local numbervar avtime:= average({@Preventive Hours},{EQUIPMENT_MNT_V.EQUIPMENT_ID});
local numbervar hour:= avtime/3600;

The int() tells the formula to truncate and only show integers. By using only hours in the original formula, you were losing the minutes that would add the decimals also.

-LB


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top