Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Check if fraction exist ?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Tue Aug 04, 2015 11:06 pm    Post subject: Check if fraction exist ? Reply with quote

Hi,

I search solution to get if fraction exist, the value of fraction is needed for me.

The original value is byte.
A this time i check is fraction exist like this:

Dim Value as byte
Dim a as single
Value= 30
a = Value / 8 ' 3,75
If frac(a) > = 0 Then
....
End If

Another simple method exist without using single variable ?

Thanks
Olivier

(BASCOM-AVR version : 2.0.7.9 , Latest : 2.0.7.8 )
Back to top
View user's profile
Plons

Bascom Member



Joined: 24 May 2005
Posts: 435
Location: Hilversum - The Netherlands

netherlands.gif
PostPosted: Wed Aug 05, 2015 12:06 am    Post subject: Reply with quote

Use Modulo math: see Bascom Help "mod"
_________________
Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel"
Back to top
View user's profile
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Wed Aug 05, 2015 1:19 am    Post subject: Reply with quote

Many thanks.

Bye
Olivier
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Wed Aug 05, 2015 9:50 am    Post subject: Reply with quote

I had some problem with the use of modulo with single and double, maybe in the last version is fixed
but , sorry I forgot the name of the friend who gave me the solution but it is clever , very simple and works for all kind of variable (change the dim) !

Function Modsingle(byval Number As Single , Byval Modulo As Single) As Single
While Number > Modulo
Number = Number - Modulo
Wend
Modsingle = Number
End Function

jp
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum