Re: INT()

From: Wilson Thomas (wilson_at_indomel.com)
Date: 05/13/04


Date: Thu, 13 May 2004 13:11:31 -0700

One more doubt

Everything is fine in command window or a new program. This is only
happening within this particular application.

Wilson

"Rush Strong" <rush.strong]@[verizon.net> wrote in message
news:ugNjGGJOEHA.1348@TK2MSFTNGP12.phx.gbl...
> What's probably happening is that the calculated value of VarTime/60 -
when
> converted to binary and back and back to decimal - isn't exactly 5, but is
> (perhaps) 4.99999884998297999, and INT() properly returns 4.
>
> You can minimize this error by increasing the relative size of your
numbers,
> rounding, then shrinking them back. None of this is tested, but you might
> try:
>
> LPARAMETERS VarTime
> VarTime = VarTime / 60
> nVar1 = VarTime / 60 && nVar1 = 4.99999884998297999
> nVar1 = nVar1 * 100 && nVar1 = 499.999884998297999
> nVar1 = INT(nVar1) && nVar1 = 499
> nVar1 = nVar1/100 && nVar1 = 4.99
> nVar1 = ROUND(nVar1,0) && nVar1 = 5.0
>
> Of course, you can string the operations together:
>
> LPARAMETERS VarTime
> VarTime = VarTime / 60
> nVar1 = ROUND(INT(100 * VarTime / 60), -2) / 100
>
> - Rush
>
> "Wilson Thomas" <wilson@indomel.com> wrote in message
> news:40a2ca0d$0$31367$afc38c87@news.optusnet.com.au...
> > Friends,
> >
> > This is the entire code. This program created a numeric value to HH:MM
> > format time I am using VFP6 and Access database
> >
> > -- bof()
> > LPARAMETERS VarTime
> > VarTime = VarTime / 60
> > nVar1 = VarTime / 60
> > nVar1=INT(nVar1) && here is the error
> > nVar2=VarTime - (nVar1*60)
> > nVar1=ALLTRIM(STR(nVar1))
> > nVar2=ALLTRIM(STR(nVar2))
> > nVar1=IIF(LEN(nVar1)=1,"0"+nVar1,nVar1)
> > nVar2=IIF(LEN(nVar2)=1,"0"+nVar2,nVar2)
> > VarTime=nVar1+':'+nVar2
> > RETURN VarTime
> > -- eof()
> >
> > Method - 1
> > -------------
> > If I run this, the answer is 04:60, but it should be 05:00. Both in_time
> and
> > out_time are in DATETIME format and the difference is 18000.
> > nVal = timesheet.out_time - timesheet.in_time
> > REPL tot_worked WITH oApp.MakeChrTime(nVal)
> >
> > Method - 2
> > -------------
> > If I run this, the anwer is 05:00, which is perfect
> > nVal = 18000
> > REPL tot_worked WITH oApp.MakeChrTime(nVal)
> >
> > Everything was perfect until last day for many years. It just started by
> > yesterday and I don't know what I did wrong. I tried what Rick and Fred
> > suggested. I am sure that I did not change any VFP environment variables
> > recently, but a lot of changes to the access table where
> "timesheet.in_time"
> > and "timesheet.out_time" is retrieved via DSN.
> >
> > This is the SQL I used
> > set date to ymd
> > cSql = "SELECT * FROM timesheet WHERE emp_id = '" + cEmpID + ;
> > "' AND pdate BETWEEN #" + DTOC(dStart) + "# AND #" + DTOC(dEnd) +
"#
> "
> > + ;
> > " ORDER BY pdate "
> > set date to dmy
> >
> > Any help would be much appreciated as my development is almost in halt.
> >
> > Wilson
> >
> >
>
>