我正在开展一个将货币价值转化为文字的项目。我发现了一些代码可以帮助我进行这种转换(以及实现上一个问题中的一些部分)并且代码工作正常并完成了我需要的...但是我得到的问题是Visual Basic继续围绕我的TEXT转换。
我最初的变量是Doubles,读到Decimals倾向于保留值并将所有内容移动到Decimal,但它仍然将我的单词转换为1。我还试图在任何转换仍然发生之前删除小数位,但文本字仍然得到了整理。例如,如果我在支票中输入14,508.85,则文本转换会吐出“十四,五千九百和85/100”
单步调试程序,看起来在使用percentConvert函数中的Modulus调用时,值正在改变。 Mod是程序(类项目)的要求。有没有我想念的东西? imgur.com/Nrym9qy
感谢您的帮助!
代码如下
Public Class Check
Dim checkValue As Decimal
Dim tempValue As Decimal
Dim result As String = ""
Dim temp As Decimal
Dim change As String = ""
Dim tempString As String = ""
Dim tempChange As Decimal
Private Function hundredsConvert(ByVal num As Decimal) As String
Static teens() As String = {"Zero", "One",
"Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Eleven", "Twelve",
"Thirteen", "Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eightteen", "Nineteen"}
Static tens() As String = {"Twenty",
"Thirty", "Forty", "Fifty", "Sixty", "Seventy",
"Eighty", "Ninety"}
' If the number is 0, return an empty string.
If num = 0 Then Return ""
' Handle the hundreds digit.
Dim digit As Decimal
Dim result As String = ""
If num > 99 Then
digit = num \ 100
num = num Mod 100
result = teens(digit) & " Hundred"
End If
' If num = 0, we have hundreds only.
If num = 0 Then Return result.Trim()
' See if the rest is less than 20.
If num < 20 Then
' Look up the correct name.
result &= " " & teens(num)
Else
' Handle the tens digit.
digit = num \ 10
num = num Mod 10
result &= " " & tens(digit - 2)
' Handle the final digit.
If num > 0 Then
result &= " " & teens(num)
End If
End If
Return result.Trim()
End Function
Private Function numToString(ByVal num As Decimal) As String
'Get the change'
change = num.ToString
change = change.Substring(change.IndexOf(".") + 1) + "/100"
tempString = num.ToString
tempString.Remove(tempString.IndexOf(".") + 2)
num = Decimal.Parse(tempString)
Static groups() As String = {" ", "Thousand ", "Million",
"Billion", "Trillion", "Quadrillion", "?", "??",
"???", "????"}
Dim result As String = ""
'Process the groups, smallest first.'
Dim quotient As Decimal
Dim remainder As Decimal
Dim group_num As Decimal = 0
Do While num > 0
'Get the next group of three digits.'
quotient = num \ 1000
remainder = num Mod 1000
num = quotient
'Convert the group into words.'
result = hundredsConvert(remainder) &
" " & groups(group_num) &
result
'Get ready for the next group.'
group_num += 1
Loop
'Remove the trailing ", ".
If result.EndsWith(", ") Then
result = result.Substring(0, result.Length - 2)
End If
Return result
End Function
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
'Dim declarations'
'Convert check value from a text field to a double'
Try
checkValue = txtCheckAmount.Text
Catch ex As InvalidCastException
MessageBox.Show("You must enter a numbers to write a check.")
End Try
lblWrittenDollars.Text = numToString(checkValue) & "and " & change
If checkValue = 0 Then
MessageBox.Show("You must have some value in order to write a check.")
txtCheckAmount.Clear()
lblWrittenDollars.Text = ""
Else
Dim finalize = MessageBox.Show("You have specified that you want to write a check for " & checkValue & "?", "", MessageBoxButtons.YesNo)
If finalize = DialogResult.No Then
txtCheckAmount.Clear()
lblWrittenDollars.Text = ""
ElseIf finalize = DialogResult.Yes Then
End If
End If
checkValue = 0
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub txtPayOrderTo_TextChanged(sender As Object, e As EventArgs) Handles txtPayOrderTo.TextChanged
End Sub
End Class
答案 0 :(得分:1)
在这种情况下,请确保在调用require(devtools)
install_github("shabbychef/madness")
require(madness)
xmat <- matrix(rnorm(16),ncol=4)
xmad <- madness(xmat)
detv <- det(xmad)
# detv is a list. I want it to be a madness object:
str(detv)
what_i_want <- detv[[1]]
str(what_i_want)
之前在您的小数值上调用Math.Floor
。对于非负值,这将为您提供十进制的向下舍入整数部分,允许您将其转换为文本。祝你好运!