bob bob - 1 month ago 10
Vb.net Question

How to remove decimal from variable in vb.net

I have created a code to work out pay of workers, and to - 1 of pay for charity if it is over 100, and every 10 over 100 -1. But I need to get rid of the decimal with new pay variable. At the end of the if function

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

Answer

Use the Math.Floor function to round down

SO if newpay was 3.6

Math.Floor(newpay)

will return 3

SO

Use the result of this function

donation = donation + Math.Floor(newpay)

OR

newpay = Math.Floor(newpay)
Comments