By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,254 Members | 2,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,254 IT Pros & Developers. It's quick & easy.

Converting Integer to Double

P: 33
i'm on my way on learning a new language vb .net and i have a hard time figuring out what might be the solution. Heres my code.

Expand|Select|Wrap|Line Numbers
  1.    Dim x as integer = 4
  2.         Dim y as integer = 8
  3.         Dim z As Integer = x / y
  4.         ' i could just declare z as double if i want to but i dont want to do that
  5.         ' i also tried to use convert to double
  6.         'z = Convert.ToDouble(z) but return 0 as result instead of 0.5
  7.         Dim result As Double
  8.         Double.TryParse(z, result)
  9.         Console.WriteLine(result)
  10.         Console.ReadLine()
  11.  
Oct 14 '14 #1

✓ answered by Rabbit

z is an integer. It can't store a fraction. Therefore the fractional is dropped before it is stored in z. There's no fraction to parse or convert.

I don't understand why you don't want to declare z as a double when you seem perfectly fine with creating an unnecessary result variable, it doesn't make sense.

Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,366
z is an integer. It can't store a fraction. Therefore the fractional is dropped before it is stored in z. There's no fraction to parse or convert.

I don't understand why you don't want to declare z as a double when you seem perfectly fine with creating an unnecessary result variable, it doesn't make sense.
Oct 14 '14 #2

P: 33
im just trying if it can be done sir. im just experimenting with them. thank you for helping me out.
Oct 14 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.