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)
この関数は、ラベルの 0.5 を 1/2 に変換します 関数は 0 1/2 を返します 0 の変更を省略するには、"Whole" を返さないでください
于 2013-06-27T06:25:26.797 に答える
0
Label を使用する代わりに RichTextBox を使用するより良いオプションを見つけました。RichTextBox をフォームにドラッグし、ショートカット キーを使用して分数を入力します。
于 2013-06-27T03:47:18.753 に答える