我必须使用什么方法来编写分数,例如使用VB.Net在标签中½?
答案 0 :(得分:0)
我找到了一个更好的选择,即使用RichTextBox而不是使用Label。将RichTextBox拖到Form上,然后使用快捷键键入fraction。
答案 1 :(得分: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)
此功能会在标签中将0.5转换为1/2 该功能将返回0 1/2 要省略0更改 - 不要返回“整体”