Sunday, June 06, 2010

Function SetMaxNumberOfDecimals()

The problem:
You has to show data (doubles) to the user but you don't know the size of the data.
if data is 0.34567890123 then you don't want to show all the decimals you might want to show 0.346.
Ok, then you user .Format(MyDbl,"F3"). But if the data in is 12345.6789012345 you doesn't want the decimals
to be shown 12345.679 because you doesn't have that kind of resolution of you measured data.

The Fix:
We make a function that limits the number of decimals and looks for number of  significant digits.

  ''' <Summary>>
    ''' Limit number of decimal shown for a Double
    ''' In (0,3) -> 0.000, In (33.456789,3) -> 33.45, In (334.56743,3) -> 334.6)
    ''' In (12345.12345,6) -> 12345.1
    ''' </Summary>>
    ''' <param name="myVal">Value to make string of</param>

    ''' String with limited number of decimals.</returns>
    ''' <remarks></remarks>    

Function SetMaxNumberOfDecimals(ByVal myVal As Double, ByVal decimals As Integer) As String
        Dim x As Double = 0
        ' Get number of power of 10, exclude 0
        If myDbl <> 0 Then
            x = Math.Log10(Math.Abs(myDbl))
        End If
        ' Round number of PowerOf10
        x = Math.Floor(x)

        ' Calc number of decimal and handle exceptions
        x = decimals - x
        If x < 0 Then x = 0
        If x > decimals Then x = decimals

        Dim z As String = "F" + x.ToString
        Return Format(myVal, z)

    End Function

MySQL to MariaDB

 Here is a good description how to migrate to MariaDb MySQL to MariaDb Example of how to dump data from MySQL port=3307: mysqldump --user=ro...