![]() |
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 |
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() ) |
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 |
number testing
Oops, meant "Fractional"
In article , JE McGimpsey wrote: MsgBox "Fractional: |
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 |
All times are GMT +1. The time now is 02:03 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com