|
||||||
| C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
doing a simple calculation using C#. I am setting distance = speedConv / 3600.
speedConv is between 0 and 60. When I print out all the values speedConv, for example is 30...but distance is always 0. I have calculated several values and they are in the area of .005, which should be well within the range of a double. Does anyone know of any reason this value would be getting rounded to 0? Thanks |
| Sponsored Links |
|
|
|
|||
|
distance and speedConv are both doubles.
I know the printing method works because when I print out another double (MPG) it prints out as a number similar to 50.22342123 So, that tells me that there should 1) be plenty of decimal places and 2) not be a problem with the printing. It's almost like it's taking a number that is less than 1 and rounding it to zero for unknown reasons. Oh, and this is a debug print. |
|
|||
|
its funny~
I have do something similar but I cannot get this error e.g. double distance; double speedConv; for (speedConv = 0; speedConv < 30; speedConv++) { distance = speedConv / 3600; Debug.WriteLine(distance); } or may you point out where is the difference between us? |
| Sponsored Links |
|
|
|
|||
|
Quote:
Right now I'm generating random data to test my code, so they are never the same number. That should not affect the test. What error are you getting? I don't get an error, I just get a distance of 0. |
|
|||
|
I figured it out, but I think it's stupid.
apparently if you divide a double by an int literal C# thinks it would be smart to just change that thar double output to an int. dunno why the developers thought that was a good idea, but changing it to 3600.0 fixed it. There wasn't even a warning for the loss of precision. |
|
|||
|
I'm not using two integer values tho.
I'm dividing a double by an integer. it's stupid that 1) the compile goes to the less precise result and 2) does not produce a warning about loss of precision. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strange Characters. | bladactania | C and C++ | 2 | 04-03-2008 08:09 AM |
| Strange but i need it. | mandriva | Website Design | 4 | 11-10-2007 11:29 AM |
| Strange error in update app | McMillan0520 | C# Programming | 1 | 08-08-2007 11:52 AM |
| Strange DLL Error, creating controls | ChrisPepper1989 | C and C++ | 0 | 02-26-2007 04:37 PM |