+ Reply to Thread
Results 1 to 3 of 3

How do I isolate the Fractional part of a number in Excel VB?

  1. #1
    Cumulous
    Guest

    How do I isolate the Fractional part of a number in Excel VB?


    I'm a novice writing a VB program in Excel 2003, and I need to isolate
    the fractional part of a number. In other words...

    Input: 23.0891467
    Output: 0.0891467


    The only way I know of to do this is (Result = Input Mod 1). The
    problem, is that while the Mod Operator works as a Worksheet Function - when
    used as a VB Operator, Excel truncates the fractional portion of the result.
    This, of course, makes it useless to me.


    I need to know the best way to isolate the fractional portion of a
    number (with maximum precision), that will work in Excel VB.

    Any help will be appreciated! Thanks!



  2. #2
    Dave Peterson
    Guest

    Re: How do I isolate the Fractional part of a number in Excel VB?

    Dim Num as double
    num = 23.0891467
    num = num - int(num)


    Is one way.


    Cumulous wrote:
    >
    > I'm a novice writing a VB program in Excel 2003, and I need to isolate
    > the fractional part of a number. In other words...
    >
    > Input: 23.0891467
    > Output: 0.0891467
    >
    > The only way I know of to do this is (Result = Input Mod 1). The
    > problem, is that while the Mod Operator works as a Worksheet Function - when
    > used as a VB Operator, Excel truncates the fractional portion of the result.
    > This, of course, makes it useless to me.
    >
    > I need to know the best way to isolate the fractional portion of a
    > number (with maximum precision), that will work in Excel VB.
    >
    > Any help will be appreciated! Thanks!


    --

    Dave Peterson

  3. #3
    Toppers
    Guest

    RE: How do I isolate the Fractional part of a number in Excel VB?

    Dim input as double, output as double

    Output=Input-int(Input)

    Sub GetFraction()
    Dim x As Double, y As Double
    x = 23.0891467
    y = x - Int(x)
    Debug.Print y
    End Sub

    y=8.91467000000006E-02
    "Cumulous" wrote:

    >
    > I'm a novice writing a VB program in Excel 2003, and I need to isolate
    > the fractional part of a number. In other words...
    >
    > Input: 23.0891467
    > Output: 0.0891467
    >
    >
    > The only way I know of to do this is (Result = Input Mod 1). The
    > problem, is that while the Mod Operator works as a Worksheet Function - when
    > used as a VB Operator, Excel truncates the fractional portion of the result.
    > This, of course, makes it useless to me.
    >
    >
    > I need to know the best way to isolate the fractional portion of a
    > number (with maximum precision), that will work in Excel VB.
    >
    > Any help will be appreciated! Thanks!
    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1