CLEAR SET DECIMALS TO 18 LOCAL lnRound lnRound = 15 FOR i = 1 TO 3 STEP .1 * Use these debugout's to see the 'pure' results. *!* debugout i *!* debugout round( i, lnRound) *!* debugout PaulRound( i, lnRound) *!* debugout RickRound(i, lnRound) *!* debugout MikeRound(i, lnRound) * Use these debugout's to format the results * for easier comparison. DEBUGOUT "i = " + LTRIM( STR( i, 20, 18)) DEBUGOUT "VFP Round = " + LTRIM( STR( ROUND( i, lnRound), 20, 18)) DEBUGOUT "PaulRound = " + LTRIM( STR( PaulRound( i, lnRound), 20, 18)) DEBUGOUT "RickRound = " + LTRIM( STR( RickRound(i, lnRound), 20, 18)) DEBUGOUT "MikeRound = " + LTRIM( STR( MikeRound(i, lnRound), 20, 18)) DEBUGOUT " " ENDFOR SET DECIMALS TO 2 RETURN FUNCTION PaulRound( tnNumber, tnDecimals) RETURN ROUND(VAL(ALLTRIM(STR(tnNumber,20,tnDecimals+1))),tnDecimals) FUNCTION RickRound( tnNumber, tnDecimals) LOCAL lnX lnX = ( ( ( tnNumber * 10^tnDecimals) + .5) / 10^tnDecimals) RETURN lnX - ( lnX % (1 / 10^tnDecimals)) FUNCTION MikeRound(tnNumber, tnDecimals) RETURN ROUND( ( INT( tnNumber*(10^15)) + .5 ) / (10^15), tnDecimals)The results are as follows. Note the error in the value of 'i' beginning with the sixth iteration.
i = 1.000000000000000000 VFP Round = 1.000000000000000000 PaulRound = 1.000000000000000000 RickRound = 1.000000000000000000 MikeRound = 1.000000000000001000 i = 1.100000000000000000 VFP Round = 1.100000000000000000 PaulRound = 1.100000000000000000 RickRound = 1.100000000000000000 MikeRound = 1.100000000000001000 i = 1.200000000000000000 VFP Round = 1.200000000000000000 PaulRound = 1.200000000000000000 RickRound = 1.200000000000000000 MikeRound = 1.200000000000001000 i = 1.300000000000000000 VFP Round = 1.300000000000000000 PaulRound = 1.300000000000000000 RickRound = 1.300000000000000000 MikeRound = 1.300000000000001000 i = 1.400000000000000000 VFP Round = 1.400000000000000000 PaulRound = 1.400000000000000000 RickRound = 1.400000000000000000 MikeRound = 1.400000000000001000 i = 1.500000000000000000 VFP Round = 1.500000000000001000 PaulRound = 1.500000000000000000 RickRound = 1.500000000000001000 MikeRound = 1.500000000000001000 i = 1.600000000000001000 VFP Round = 1.600000000000001000 PaulRound = 1.600000000000001000 RickRound = 1.600000000000000000 MikeRound = 1.600000000000001000 i = 1.700000000000001000 VFP Round = 1.700000000000001000 PaulRound = 1.700000000000001000 RickRound = 1.700000000000001000 MikeRound = 1.700000000000001000 i = 1.800000000000001000 VFP Round = 1.800000000000001000 PaulRound = 1.800000000000001000 RickRound = 1.800000000000001000 MikeRound = 1.800000000000001000 i = 1.900000000000001000 VFP Round = 1.900000000000001000 PaulRound = 1.900000000000001000 RickRound = 1.900000000000001000 MikeRound = 1.900000000000001000 i = 2.000000000000001000 VFP Round = 2.000000000000001000 PaulRound = 2.000000000000001000 RickRound = 2.000000000000001000 MikeRound = 2.000000000000001000 i = 2.100000000000001000 VFP Round = 2.100000000000001000 PaulRound = 2.100000000000001000 RickRound = 2.100000000000001000 MikeRound = 2.100000000000002000 i = 2.200000000000001000 VFP Round = 2.200000000000001000 PaulRound = 2.200000000000001000 RickRound = 2.200000000000001000 MikeRound = 2.200000000000002000 i = 2.300000000000001000 VFP Round = 2.300000000000001000 PaulRound = 2.300000000000001000 RickRound = 2.300000000000001000 MikeRound = 2.300000000000002000 i = 2.400000000000001000 VFP Round = 2.400000000000001000 PaulRound = 2.400000000000001000 RickRound = 2.400000000000001000 MikeRound = 2.400000000000002000 i = 2.500000000000001000 VFP Round = 2.500000000000002000 PaulRound = 2.500000000000001000 RickRound = 2.500000000000002000 MikeRound = 2.500000000000002000 i = 2.600000000000001000 VFP Round = 2.600000000000002000 PaulRound = 2.600000000000001000 RickRound = 2.600000000000001000 MikeRound = 2.600000000000002000 i = 2.700000000000002000 VFP Round = 2.700000000000002000 PaulRound = 2.700000000000002000 RickRound = 2.700000000000001000 MikeRound = 2.700000000000002000 i = 2.800000000000002000 VFP Round = 2.800000000000002000 PaulRound = 2.800000000000002000 RickRound = 2.800000000000002000 MikeRound = 2.800000000000002000 i = 2.900000000000002000 VFP Round = 2.900000000000002000 PaulRound = 2.900000000000002000 RickRound = 2.900000000000002000 MikeRound = 2.900000000000002000