Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
number testing
Hi all,
What is the quickest way to test if a number is fractiona, ie, 2.5, 7.99999, 5.5, 8.25...etc regardless whether the number is even or odd or prime. I want to be able to tell, when the code is running that a number is a whole number or not, even the the formatting is for example 25.0, in this case the number is 25, even though the format is s25.0, I want to code to be able to differentiate a real fractional number as oppose to one that is just formatting in nature. Thanks for your suggestions and code samples. Ben |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
number testing
You just need to compare the value with its rounded value...
example if (x = round(x)) then ... (in place of round try any function you like for that purpose, maybe int() ) |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
number testing
I don't know about fastest, but this works (and operations are usually
faster than methods): If s \ 1 = s Then MsgBox "Integral" Else MsgBox "Fractional: End If That said, there are lots of floating point operations on fractional values, that, due to the inherent nature of binary arithmetic, while arithmetically resulting in an integral value, have slight rounding errors that return in a fractional result. In article , "Ben" wrote: Hi all, What is the quickest way to test if a number is fractiona, ie, 2.5, 7.99999, 5.5, 8.25...etc regardless whether the number is even or odd or prime. I want to be able to tell, when the code is running that a number is a whole number or not, even the the formatting is for example 25.0, in this case the number is 25, even though the format is s25.0, I want to code to be able to differentiate a real fractional number as oppose to one that is just formatting in nature. Thanks for your suggestions and code samples. Ben |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
number testing
Oops, meant "Fractional"
In article , JE McGimpsey wrote: MsgBox "Fractional: |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
number testing
Thanks dcdc2 and JE.
Those are great suggestions Ben "Ben" wrote in message ... Hi all, What is the quickest way to test if a number is fractiona, ie, 2.5, 7.99999, 5.5, 8.25...etc regardless whether the number is even or odd or prime. I want to be able to tell, when the code is running that a number is a whole number or not, even the the formatting is for example 25.0, in this case the number is 25, even though the format is s25.0, I want to code to be able to differentiate a real fractional number as oppose to one that is just formatting in nature. Thanks for your suggestions and code samples. Ben |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
TESTING | Excel Worksheet Functions | |||
Testing | Excel Discussion (Misc queries) | |||
Testing | Excel Discussion (Misc queries) | |||
testing | Excel Worksheet Functions | |||
testing whether a character is a letter or number | Excel Programming |