我已经创建了一个代码来计算工人的工资,如果超过100,我会创建一个慈善机构的薪酬,而每100个就超过100个-1。但我需要用新的薪酬变量去除小数。在if函数结束时
Dim donation As Single
Dim newpay As Single
Dim hourlyRate As Decimal
Dim pay As Decimal
Dim hours As Single
Sub Main()
Console.WriteLine("how many hours have you worked this week?")
hours = Console.ReadLine
Console.WriteLine("what is your hourly pay?")
hourlyRate = Console.ReadLine
pay = hours * hourlyRate
newpay = pay
If pay > 100 Then
pay = pay - 1
newpay = newpay - 100
donation = donation + 1
newpay = newpay / 10
Math.Floor(newpay)
pay = pay - newpay
donation = donation + newpay
End If
Console.WriteLine("you earned £" & pay & " and donated £" & donation & " to charity")
Console.ReadLine()
End Sub
答案 0 :(得分:3)
使用Math.Floor
功能围绕向下
如果newpay是3.6
Math.Floor(newpay)
将返回3
SO
使用此功能的结果
donation = donation + Math.Floor(newpay)
OR
newpay = Math.Floor(newpay)