Turn decimal into Vb minutes

Asked

Viewed 221 times

0

Well I know that if I take for example 4.70 and turn the ".70" in minutes, I have q take the 0.70 ( number after the comma ) and multiplied by 60, that would give 42, in value of hours would be 4:42

How do I apply this in VB? how do I get the number after the comma, multiplied by 60?

2 answers

1


You can take the decimal part of the number this way:

parte_decimal = (valor - Int(valor))

So you subtract the whole part, leaving only the decimal part.

  • 1

    That’s right, thank you very much! the code I used if anyone is interested in turning decimal to time Dim parte_decimal As Double parte_decimal = (Textbox1.Text - Int(Textbox1.Text)) Textbox2.Text = part_decimal * "60" Textbox3.Text = Int(Textbox1.Text) & ":" & Textbox2.Text & ""

1

A good solution would be to use the conversion function to INT in its variable. So the difference between the two (Real - Integer) would provide you the number after the comma.

Example:

Valor_Total = 4,70

valor_decimal = (Valor_Total - Int(Valor_Total))
total_minutos = valor_decimal * 60

MessageBox.Show ("Total de minutos: " + (Int(Valor_Total)ToString() + ":" + total_minutos.ToString())

Total Minutes: 4:42 am

Well this is only one solution, but there are many other available!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.