• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing from Double to Int  RSS feed

 
Shane Lilly
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have an array of double values and i am then using this array within a switch statement...
switch(timevaluesarray(iCount) {
...........
}
When I compile the code I get the error 'loss of precision', where a double is found but and int is required. Is there a simple line of code that can change the values in the array from double to int??
The values being fed into the array are required to be double so i can't change them before they are put into the array.
Thanks for any help!
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am guessing that the method timevaluesarray(iCount) returns a double value, if that is the case you can always try casting like this:
switch((int)timevaluesarray(iCount) {
...........
}
[ March 13, 2004: Message edited by: Vicken Karaoghlanian ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, be very clear about what the compiler warning concerning the possible loss of precision means. Values that were different will match the same case. In other words, casting a double to an int and then switching on the resulting value might not work as hoped since values like 2.4 and 2.3 will both match case 2 in the switch construct.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!