I was thinking that the result of 50\1000 was 0.05 ........
-
Hi all, I have a strange problem: Dim X As Single = 50 Dim Y As Single = 1000 Dim Z As Single = X \ Y Why Z return me 0.0 as result of operation instead that 0.05? If X is 100, then the result is correct (0.1). I also tried to dimensione variables as Double, and to use Double.Parse instruction, but without resolve the problem. All this is in a VB .Net Compact Framework routine. Surely the problem is a "false" problem, but now I have a momentary "mind vacuum"..... Thanks for help.
modified on Sunday, January 17, 2010 12:32 PM
-
Hi all, I have a strange problem: Dim X As Single = 50 Dim Y As Single = 1000 Dim Z As Single = X \ Y Why Z return me 0.0 as result of operation instead that 0.05? If X is 100, then the result is correct (0.1). I also tried to dimensione variables as Double, and to use Double.Parse instruction, but without resolve the problem. All this is in a VB .Net Compact Framework routine. Surely the problem is a "false" problem, but now I have a momentary "mind vacuum"..... Thanks for help.
modified on Sunday, January 17, 2010 12:32 PM
Single is a single precision float (from MSDN). I think this should explain. You can use decimal and I think it would give correct result.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
Single is a single precision float (from MSDN). I think this should explain. You can use decimal and I think it would give correct result.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
Hi D@nish, Single is a single precision float, but normally it returns decimal numbers. I tryed to use Decimal type (return 0D value), but the problem is not resolved yet. Here seems that the result is strangely cutted after the first decimal number.....
-
Hi all, I have a strange problem: Dim X As Single = 50 Dim Y As Single = 1000 Dim Z As Single = X \ Y Why Z return me 0.0 as result of operation instead that 0.05? If X is 100, then the result is correct (0.1). I also tried to dimensione variables as Double, and to use Double.Parse instruction, but without resolve the problem. All this is in a VB .Net Compact Framework routine. Surely the problem is a "false" problem, but now I have a momentary "mind vacuum"..... Thanks for help.
modified on Sunday, January 17, 2010 12:32 PM
You're using the wrong slash. The Forward Slash, /, will give the correct result. The Backslash, \, does integer division.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
You're using the wrong slash. The Forward Slash, /, will give the correct result. The Backslash, \, does integer division.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Thanks Dave, Without your help I risked to spend one week to try to resolve a false problem, and with no warranty to solve it in one week!
-
You're using the wrong slash. The Forward Slash, /, will give the correct result. The Backslash, \, does integer division.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...GENIUS I couldn't work out why it wasn't happening! Although you could have been a bit of a smartarse over that, it was nice to see you just pointed out what others failed to see!
------------------------------------ No Good Deed Goes Unpunished Clare Boothe Luce