Stimulsoft Reports.Net
www.stimulsoft.com

Welcome Guest Search | Active Topics | Members | Log In | Register

Fractions Options
Troy7k
Posted: Thursday, March 11, 2010 9:47:52 PM
Rank: Newbie
Groups: Member

Joined: 3/10/2009
Posts: 8
Location: Delaware, OH
As a manufacturer we required a fraction conversion function and not a 1/25 fraction but an actual 1/32 or 1/16 fraction, you know, one that shows up on a tape measure. I thought I would share the code that I came up with and would appreciate any critique of the code. I have two different functions, one for 1/32 and on for 1/16. I do realize that I could have simply checked the 'Accuracy' variable but there are many users who prefer the software to work in 6 or 7 places of accuracy but print in either 1/16 or 1/32 increments. I've also added a .01 to the value since I didn't want to write a extra code to look for .9999, .4999, .65, etc .... I couldn't really find a good rounding function and this worked well for our application.

Thanks in advance for your critique, I'm not terribly familiar with this language yet.

Function The32Fraction (Value as double) as string
dim WholeNumber as String
dim Numerator as integer
dim FractionPart as string
dim CompleteFractionalNumber as string
Value = Value +.01
WholeNumber = cstr(Math.Truncate(Value))
Numerator = Math.Truncate((Value-Math.Truncate(Value))*32)
Select Case Numerator
Case 1 : FractionPart = "1/32"
Case 2 : FractionPart = "1/16"
Case 3 : FractionPart = "3/32"
Case 4 : FractionPart = "1/8"
Case 5 : FractionPart = "5/32"
Case 6 : FractionPart = "3/16"
Case 7 : FractionPart = "7/32"
Case 8 : FractionPart = "1/4"
Case 9 : FractionPart = "9/32"
Case 10 : FractionPart = "5/16"
Case 11 : FractionPart = "11/32"
Case 12 : FractionPart = "3/8"
Case 13 : FractionPart = "13/32"
Case 14 : FractionPart = "7/16"
Case 15 : FractionPart = "15/32"
Case 16 : FractionPart = "1/2"
Case 17 : FractionPart = "17/32"
Case 18 : FractionPart = "9/16"
Case 19 : FractionPart = "19/32"
Case 20 : FractionPart = "5/8"
Case 21 : FractionPart = "21/32"
Case 22 : FractionPart = "11/16"
Case 23 : FractionPart = "23/32"
Case 24 : FractionPart = "3/4"
Case 25 : FractionPart = "25/32"
Case 26 : FractionPart = "13/16"
Case 27 : FractionPart = "27/32"
Case 28 : FractionPart = "7/8"
Case 29 : FractionPart = "29/32"
Case 30 : FractionPart = "15/16"
Case 31 : FractionPart = "31/32"
Case Else : FractionPart = ""
End Select
If value < 1 Then
CompleteFractionalNumber = FractionPart
Elseif FractionPart = "" Then
CompleteFractionalNumber = WholeNumber
Else
CompleteFractionalNumber = WholeNumber + "-" + FractionPart
End If
Return CompleteFractionalNumber
End Function

Function The16Fraction (Value as double) as string
dim WholeNumber as String
dim Numerator as integer
dim FractionPart as string
dim CompleteFractionalNumber as string
Value = Value +.01
WholeNumber = cstr(Math.Truncate(Value))
Numerator = Math.Truncate((Value-Math.Truncate(Value))*16)
Select Case Numerator
Case 1 : FractionPart = "1/16"
Case 2 : FractionPart = "1/8"
Case 3 : FractionPart = "3/16"
Case 4 : FractionPart = "1/4"
Case 5 : FractionPart = "5/16"
Case 6 : FractionPart = "3/8"
Case 7 : FractionPart = "7/16"
Case 8 : FractionPart = "1/2"
Case 9 : FractionPart = "9/16"
Case 10 : FractionPart = "5/8"
Case 11 : FractionPart = "11/16"
Case 12 : FractionPart = "3/4"
Case 13 : FractionPart = "13/16"
Case 14 : FractionPart = "7/8"
Case 15 : FractionPart = "15/16"
Case Else : FractionPart = ""
End Select
If value < 1 Then
CompleteFractionalNumber = FractionPart
Elseif FractionPart = "" Then
CompleteFractionalNumber = WholeNumber
Else
CompleteFractionalNumber = WholeNumber + "-" + FractionPart
End If
Return CompleteFractionalNumber
End Function

Andrew
Posted: Friday, March 12, 2010 3:48:44 PM
Rank: Advanced Member
Groups: Stimulsoft Team

Joined: 6/9/2006
Posts: 1,133
Hello,

Unfortunately, from your post we did not exactly understood your task.

Thank you.
Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum Rss Feed : RSS

Powered by Yet Another Forum.net version 1.0.1 - 2/27/2006
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.028 seconds.