VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts fractions to decimals Im new to vb and this is my first complete module i got tired of loo

by Chuck Pershall (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 23rd August 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts fractions to decimals Im new to vb and this is my first complete module i got tired of looking for this code so i finally got the

Rate Converts fractions to decimals Im new to vb and this is my first complete module i got tired of loo



'use code like this whatever=fract2dec(text1.text)
'can be used in several different ways but im using it in a mathmatical program
'so that input from a user can be a fraction and it can be used in a 
'math argument
Dim l As Variant, r As Variant, f As String, length As Single, d As Single, tens As Single
'If there is no fraction do nothing
If IsNumeric(x) Then
fract2dec = x
Exit Function
End If
'get fraction
f = right(x, 2)
'seperate fraction from whole number
'check for single or double digit in fraction and convert fraction to decimal
If Not IsNumeric(f) Then
f = right(x, 3)
r = Mid(f, 1, 1) / Mid(f, 3, 3)
length = Len(x) - 3
l = left(x, length)
Else
f = right(x, 4)
r = Mid(f, 1, 1) / Mid(f, 3, 4)
length = Len(x) - 4
l = left(x, length)
End If

'put the whole number and the fraction together after removing the 0
length = Len(r) - 1
d = (l & right(r, length))
fract2dec = d
End Function

Download this snippet    Add to My Saved Code

Converts fractions to decimals Im new to vb and this is my first complete module i got tired of loo Comments

No comments have been posted about Converts fractions to decimals Im new to vb and this is my first complete module i got tired of loo. Why not be the first to post a comment about Converts fractions to decimals Im new to vb and this is my first complete module i got tired of loo.

Post your comment

Subject:
Message:
0/1000 characters