Main Menu

question about MOD and 0.5

Started by andrik, February 18, 2008, 02:26:09 PM

Previous topic - Next topic

andrik

Hi,

I'm using a the following to determine if the fractional range of a random number lies between 0.5 and 0.99999999etc.
(Mod(factor#,1) = 1

However when the fraction is 0.5 (for example 2.5, 5.5), Mod returns a 0, while I want it to return a 1. What can I do to catch all fractions between (and inclusive) 0.5 an 0.9999?

best regards,
Andrik

kevin

#1
 Without looking it probably doesn't support floats, so you'd have to roll your own.

PlayBASIC Code: [Select]
 print fmod(1.1,0.5)

Sync
Waitkey


Function fMod(Value#,Divider#)
if Divider#<>0
result#=Value#-(int(Value#/Divider#)*Divider#)
endif
EndFunction result#




    Note: This article is way out of date