problem with math

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vbbeginner
    New Member
    • Jan 2008
    • 9

    problem with math

    when i write
    text1.text=val( 5/10)
    the result will be .5
    i need it 1/2
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    please can you explain a little more, that is the correct mathematical result but do you actually want the text to show "1/2"

    if you are looking to convert double values to fractions a quick google would have bought up this -

    Code:
    Public Function Dec2Frac(ByVal f As Double) As String
    
            Dim df As Double
            Dim lUpperPart As Long
            Dim lLowerPart As Long
    
            lUpperPart = 1
            lLowerPart = 1
    
            df = lUpperPart / lLowerPart
            While (df <> f)
                If (df < f) Then
                    lUpperPart = lUpperPart + 1
                Else
                    lLowerPart = lLowerPart + 1
                    lUpperPart = f * lLowerPart
                End If
                df = lUpperPart / lLowerPart
            End While
            Dec2Frac = CStr(lUpperPart) & "/" & CStr(lLowerPart)
        End Function

    Comment

    • vbbeginner
      New Member
      • Jan 2008
      • 9

      #3
      How Can I Use This Function
      Sorry I Am A Beginner

      Comment

      • jg007
        Contributor
        • Mar 2008
        • 283

        #4
        Originally posted by vbbeginner
        How Can I Use This Function
        Sorry I Am A Beginner
        this function accepts a number ( double ) and returns a result as a fraction

        AnswerAsFractio n = dec2frac(number _to _convert)

        for your example -

        text1.text=dec2 frac(5/10)

        to place the funtcion into your code just paste it into the main form class

        Comment

        Working...