Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default number testing

Oops, meant "Fractional"

In article ,
JE McGimpsey wrote:

MsgBox "Fractional:

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TESTING Eamon Excel Worksheet Functions 0 July 11th 08 03:41 PM
Testing Richard Wrigley Excel Discussion (Misc queries) 0 November 1st 06 09:45 PM
Testing Tony Excel Discussion (Misc queries) 0 June 4th 05 05:39 PM
testing Juco Excel Worksheet Functions 2 January 31st 05 01:13 AM
testing whether a character is a letter or number Paul James[_3_] Excel Programming 9 February 20th 04 12:04 AM


All times are GMT +1. The time now is 07:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"