UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Is Single Number Divisible By 2, Any Version    
 
   
TimTDP
post Feb 12 2019, 03:42 AM
Post#1



Posts: 1,053
Joined: 16-June 05



I need to determine if a number (format single) is exactly divisible by 2

e.g
13.78 is (6.89)
13.79 is not (8.895)

How do I determine this with code?

Thanks in advance
Go to the top of the page
 
Vince
post Feb 12 2019, 03:52 AM
Post#2



Posts: 53
Joined: 18-August 16
From: Bristol, UK


IF x/2=INT(x/2) THEN ......

Where x is your number.
Go to the top of the page
 
cheekybuddha
post Feb 12 2019, 04:30 AM
Post#3


UtterAccess VIP
Posts: 10,908
Joined: 6-December 03
From: Telegraph Hill


What do you mean 'exactly divisible by 2'?

To me, that means that the result is a whole number, but your examples show something different:
13.78 is (6.89) <-- this is exactly divisible by 2 ??
13.79 is not (8.895) <-- should this not be 6.895 ??

confused.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
TimTDP
post Feb 12 2019, 04:39 AM
Post#4



Posts: 1,053
Joined: 16-June 05



Thanks Vince
This post has been edited by TimTDP: Feb 12 2019, 04:40 AM
Go to the top of the page
 
TimTDP
post Feb 12 2019, 04:58 AM
Post#5



Posts: 1,053
Joined: 16-June 05



13.78 is (6.89) <-- this is exactly divisible by 2 ??
13.79 is not (8.895) <-- should this not be 6.895 ??

So I guess I am looking for a return of no more than 2 decimal points
I need this for an account purpose

So I have 2 persons responsible for an account
If the account value =
13.78, then both parties pay 6.89
13.79, then one party pays 6.90 & the other 6.89
Go to the top of the page
 
cheekybuddha
post Feb 12 2019, 05:31 AM
Post#6


UtterAccess VIP
Posts: 10,908
Joined: 6-December 03
From: Telegraph Hill


OK,

CODE
If ((x / 2) * 100) MOD 2 = 0 Then
  ' Divisible by 2
Else
  ' More than 2 dp
End If


Consider using Currency datatype instead of Single for working with monetary values - it's less prone to rounding errors.

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    23rd February 2019 - 03:49 AM