Author Message

My problem is...
Round(97.45 * 10 / 100, 2) = 9.74
when it should be 9.75.

Someone Can help me ?
Thanks.

Thu, 19 Feb 2004 02:02:51 GMT
hello jose,
you should do some more calculations to get the wished result.
1st get more division by 5 before round()
2nd multiplicate the rounded result with 5
this is to get steps of .05 as you need

Thu, 19 Feb 2004 02:31:33 GMT
Hi Jose

For my needs I've made a function for that.

FUNCTION FcRound(nBetr,fk)
// usual fk = 5 if rounding to 0.5,   2 if rounding to 0.2 etc.
LOCAL n

IF nBetr <> 0
n    := Int(Abs(nBetr)*100/fk+0.5)/(100/fk)
IF nBetr < 0 ; nBetr  := -n
ELSE         ; nBetr  :=  n
ENDIF
ENDIF
RETURN nBetr

Function call:
nAmount    := FcRound(nAmount,5)

HTH

Walt

Quote:
> My problem is...
>       Round(97.45 * 10 / 100, 2) = 9.74
> when it should be 9.75.

> Someone Can help me ?
> Thanks.

Thu, 19 Feb 2004 11:43:14 GMT
1. In clipper 5.3 there is CORRECT answer

2. In DBase or FOXbase, there is WRONG answer - it seems to be bug! Use
cliper 5.3!

Thu, 19 Feb 2004 17:18:09 GMT
Hello Jose,

Quote:
> My problem is...
>       Round(97.45 * 10 / 100, 2) = 9.74
> when it should be 9.75.

Try this:
Int(97.45 * 20 + 0.5) / 20

Best regards

Otto
Bern, Switzerland

Using Clipper 5.2e, Blinker 5.10, Clip-4-Win 3.0,

Fri, 20 Feb 2004 02:43:12 GMT
ROUND( (97.45 * 10 / 100)+0,00001,2)

or Replace ROUND with ROUNDOK

FUNCTION ROUNDOK( nNumberm, nDigm)
if pcount()=1
nDigm=2
endif
RETURN (ROUND(nNumberm+iif(Nnumberm<0,-0.00001,0.00001),nDigm)

Quote:
> My problem is...
>       Round(97.45 * 10 / 100, 2) = 9.74
> when it should be 9.75.

> Someone Can help me ?
> Thanks.

Fri, 20 Feb 2004 03:55:11 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages