我必须使用什么方法在使用 VB.Net 的标签中写入分数,例如 ½?
问问题
1583 次
2 回答
0
Function GetFraction(ByVal d As Double) As String
' Get the initial denominator: 1 * (10 ^ decimal portion length)
Dim Denom As Int32 = CInt(1 * (10 ^ d.ToString.Split("."c)(1).Length))
' Get the initial numerator: integer portion of the number
Dim Numer As Int32 = CInt(d.ToString.Split("."c)(1))
' Use the Euclidean algorithm to find the gcd
Dim a As Int32 = Numer
Dim b As Int32 = Denom
Dim t As Int32 = 0 ' t is a value holder
' Euclidean algorithm
While b <> 0
t = b
b = a Mod b
a = t
End While
'Get whole part of the number
Dim Whole As String = d.ToString.Split("."c)(0)
' Return our answer
Return Whole & " " & (Numer / a) & "/" & (Denom / a)
End Function
label.text = GetFraction(0.5)
This function will convert 0.5 to 1/2 in your label The function will return 0 1/2 To omit the 0 change - do not return "Whole"
于 2013-06-27T06:25:26.797 回答
0
我找到了一个更好的选择,它使用 RichTextBox 而不是使用标签。将 RichTextBox 拖到窗体上,然后使用快捷键键入分数。
于 2013-06-27T03:47:18.753 回答