Jump to content

Rounding error?


This topic is 5687 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a calculation for a field that is not doing exactly what I expected and I cannot figure out what I am doing wrong. I am trying to calculate the total billed. The following is the calculation I use for the field "TotalBilled":

Case ( ReceivedbyBC = "retainer" ; Deposit ; IsEmpty ( StartTime ) or IsEmpty ( EndTime ); Oldtotalbilled; (Round(

Hour( EndTime - StartTime ) + Minute( EndTime - StartTime ) / 60;

2)

+

If(

GetAsNumber(EndTime) <= GetAsNumber(StartTime);

24;

0)) * HourlyRateBilled +Round ( OverdueInterest ; 2 ))

It first checks to see if the Field "ReceivedbyBC" is set to "retainer", if it is then it uses the Field "Deposit" as the total amount billed.

It then checks to see if the Fields "StartTime" and "EndTime" are empty, if it is then this client is from Old imported data and uses the Field "Oldtotalbilled" as the total amount billed.

If Fields "StartTime" and "EndTime" are valid it then calculates the time duration and multiplies it by the Field "HourlyRateBilled" and adds any overdue interest. this is rounded to 2 decimal places since I want it in the format $1.00.

The Problem is that I get rounding errors. If we assume a Hourlyratebilled of 300. No deposit and No overdue interest and Set the start time to 07:00 and end time to 07:35 I get a total billed of 174.00 instead of 175.00. I can't figure out how to correct this

Please help

Link to comment
Share on other sites

Why don't you try something simple like:

Case (

ReceivedbyBC = "retainer" ; Deposit ;

IsEmpty ( StartTime ) or IsEmpty ( EndTime ) ; Oldtotalbilled ;

Let ( [

billTime = EndTime - StartTime + ( EndTime < StartTime ) * 86400 ;

billAmt = billTime * Hourlyratebilled / 3600

] ;

Round ( billAmt + OverdueInterest ; 2 )

)

)

BTW, rounding is one thing, and formatting "as $1.00" is another. If you want currency formatting, with 2 trailing decimal places, use Format > Number... in Layout mode. Rounding is a numerical operation, and 1 rounded to 2 decimal places is still 1.

Link to comment
Share on other sites

This topic is 5687 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.