VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts a decimal to a fraction, including repeating decimals like .333333... or decimals like .47

by Redsting71 (9 Submissions)
Category: Math/Dates
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 29th January 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts a decimal to a fraction, including repeating decimals like .333333... or decimals like .4726211111... Also converts 4.56666... and

Rate Converts a decimal to a fraction, including repeating decimals like .333333... or decimals like .47



'None of the variables should contain a decimal in them. A good example of this 
'is: mystring$ = Math_DecFrac(4, 3452, 7) - will convert 4.3452777777... into a
'fraction. The answer is 391075/90000.

thefirst$ = Trim(Str(nonrepeating) + Trim(Str(repeating)))
thesecond = 10 ^ (Len(thefirst$))
thethird = 10 ^ (Len(nonrepeating))
MathFrac = Trim(Str((Val(thefirst$) - nonrepeating))) + "/" + Trim(Str((thesecond - thethird)))
wholenumber = wholenumber * Val(Trim(Str((thesecond - thethird))))
thetop = Val(Trim(Str((Val(thefirst$) - nonrepeating)))) + Val(wholenumber)
thebottom = Trim(Str((thesecond - thethird)))
Math_DecFrac = Trim(Str(thetop)) + "/" + Trim(Str(thebottom))

End Function


Download this snippet    Add to My Saved Code

Converts a decimal to a fraction, including repeating decimals like .333333... or decimals like .47 Comments

No comments have been posted about Converts a decimal to a fraction, including repeating decimals like .333333... or decimals like .47. Why not be the first to post a comment about Converts a decimal to a fraction, including repeating decimals like .333333... or decimals like .47.

Post your comment

Subject:
Message:
0/1000 characters