Link to home
Start Free TrialLog in
Avatar of tambrosi
tambrosi

asked on

VB.net help--How to

I am fairly new to VB.net and need to  know how to convert/display 16th's and 32nd's from stored db numbers.    Numbers in the are stored like below.

32.8125000    This is a 16th
27.5937500    this is a 32nd.  

I need 32.812500 to print as 32-13/16    and  27.5937500  as 27-19/32.  

Does vb.net have any internal functions to convert/display these type of numbers.
Thanks
Avatar of plusone3055
plusone3055
Flag of United States of America image

how would the program KNOW to display something as said fraction

IE
Ifi i had 5 numbers

10
9
8
7
6

how would I know that  10 should be in 32
9 should be in 16
8 should be in 32
7 should be in 16
6 should be in 32 ????
Avatar of Kyle Abrahams, PMP
There is no built in function:

You could use a pre-built function written by others:
http://www.codeproject.com/Articles/165320/Easy-Way-of-Converting-a-Decimal-to-a-Fraction
(using http://www.developerfusion.com/tools/convert/csharp-to-vb/ to convert)

Or:

You could just build a lookup table:
Dim Dec2Frac as new Dictionary(string, string)

Dec2Frac.Add(".8125", " 1/16") 'note the space in the fraction
Dec2Frac.Add(".59375", " 1/32")
Dim theNumber As String 
Dim myVal As Double = 27.59375 
theNumber = myVal.ToString() 
If theNumber.Contains("."C) Then 
      theNumber = theNumber.Replace(theNumber.ToString().Split("."C)(1), Dec2Frac(theNumber.ToString().Split("."C)(1).Trim("0"C))) 
   Else 
      theNumber = theNumber.Trim("0"C).Trim("."C) 
End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial