Results 1 to 5 of 5

Thread: seperating variable into mantissa and exponent

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    seperating variable into mantissa and exponent

    Hello

    can you guys tell me how to seperate a number into its mantissa and exponents parts

    e.g. u = 1.3e+123

    is there any way i can do something like

    mantissa = u.mantissa
    exponent = u.exponent (where u is the variable)

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: seperating variable into mantissa and exponent

    The task should be straightforward string parsing:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type NumMantExp
    4.     Exp As Integer
    5.     Mant As Double
    6. End Type
    7.  
    8.  
    9. Sub MantExp()
    10.     Dim dX As Double
    11.     Dim sX As String
    12.     Dim iX As Integer
    13.     Dim num1 As NumMantExp
    14.    
    15.     dX = -0.00234556234586 * 1E-56
    16.     sX = Format(dX, "#.##############################E+####")
    17.     iX = InStr(sX, "E")
    18.     num1.Exp = Val(Mid(sX, iX + 1, Len(sX)))
    19.     num1.Mant = Val(Left(sX, iX - 1))
    20.    
    21.     Debug.Print "mantissa = " & num1.Mant
    22.     Debug.Print "exponent = " & num1.Exp
    23. End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: seperating variable into mantissa and exponent

    thanks for the reply

    i guess

    VB Code:
    1. iX = InStr(sX, "E")

    determines the position of E, correct?

  4. #4
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: seperating variable into mantissa and exponent

    Quote Originally Posted by vb_student
    thanks for the reply

    i guess

    VB Code:
    1. iX = InStr(sX, "E")

    determines the position of E, correct?
    It does indeed.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: seperating variable into mantissa and exponent

    thanks for the reply dude

Posting Permissions

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



Click Here to Expand Forum to Full Width