[dba-VS] [dba-VB] C#, mantissa, math fun

Jim Lawrence accessd at shaw.ca
Mon Oct 16 11:43:29 CDT 2017


Hi Gustav:

Thanks for the update. I have a question about the return parameters. As it is possible to send any value to this function, how are values like strings or an empty value managed? Should the variable "Result" be initialized to a zero or have some other default value?

Jim

----- Original Message -----
From: "Gustav Brock" <gustav at cactus.dk>
To: "Development in Visual Studio" databaseadvisors.com>, "Access Developers discussion and problem solving" <accessd at databaseadvisors.com>
Sent: Monday, October 16, 2017 3:33:49 AM
Subject: Re: [dba-VS] [dba-VB] C#, mantissa, math fun

Hi all

Oops, the parameter should be a Variant to take a Decimal value which can hold op to 28 decimals:


' Returns the mantissa of a decimal number as
' a string to preserve leading zeroes.
'
' Maximum returned length of mantissa is:
'   Single:      8
'   Double:     16
'   Currency:    4
'   Decimal:    28
'
' Examples:
'   Mantissa(1234.56789)    -> "56789"
'   Mantissa(-1234.56789)   -> "56789"
'   Mantissa(1234.056789)   -> "056789"
'   Mantissa(-1234.056789)  -> "056789"
'   Mantissa(123456789)     -> ""
'   Mantissa(CDec("-0.0123456789012345678901234567"))   -> "0123456789012345678901234567"
'   Mantissa(CDbl("-0.0123456789012345678901234567"))   -> "0123456789012346"
'
' 2017-10-16. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function Mantissa( _
    ByVal Number As Variant) _
    As String
    
    Dim Result      As String
    Dim Fraction    As Variant
    
    If IsNumeric(Number) Then
        ' Convert to Decimal to prevent scientific notation of doubles and singles.
        Fraction = CDec(Number) - Fix(CDec(Number))
        If Fraction <> 0 Then
            Result = Mid(Str(Abs(Fraction)), 3)
        End If
    End If
    
    Mantissa = Result
    
End Function


/gustav

-----Oprindelig meddelelse-----
Fra: dba-VS [mailto:dba-vs-bounces at databaseadvisors.com] På vegne af Gustav Brock
Sendt: 15. oktober 2017 17:54
Til: Development in Visual Studio databaseadvisors.com>; Access Developers discussion and problem solving <accessd at databaseadvisors.com>
Emne: Re: [dba-VS] [dba-VB] C#, mantissa, math fun

Hi all

I posted a method for this in C#.
Finding the mantissa in VBA it could be like:


' Returns the mantissa of a decimal number as ' a string to preserve leading zeroes.
'
' Examples:
'   Mantissa(1234.56789)    -> "56789"
'   Mantissa(-1234.56789)   -> "56789"
'   Mantissa(1234.056789)   -> "056789"
'   Mantissa(-1234.056789)  -> "056789"
'   Mantissa(123456789)     -> ""
'
' 2017-10-15. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function Mantissa( _
    ByVal Number As Double) _
    As String

    Dim Result      As String
    Dim Fraction    As Variant

    Fraction = CDec(Number) - CDec(Fix(Number))

    If Fraction <> 0 Then
        Result = Mid(Str(Abs(Fraction)), 3)
    End If

    Mantissa = Result

End Function


/gustav

_______________________________________________
dba-VS mailing list
dba-VS at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vs
http://www.databaseadvisors.com

_______________________________________________
dba-VS mailing list
dba-VS at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vs
http://www.databaseadvisors.com



More information about the dba-VS mailing list