• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Changing from Double to Int

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic