[dba-VS] [dba-VB] C#, mantissa, math fun
Gustav Brock
gustav at cactus.dk
Mon Oct 16 05:33:49 CDT 2017
Hi all
Oops, the parameter should be a Variant to take a Decimal value which can hold op to 28 decimals:
<code>
' 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
</code>
/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 <dba-vs at 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:
<code>
' 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
</code>
/gustav
_______________________________________________
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