• 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

java.util.IllegalFormatConversionException

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This line:



generates the error.

The array is a Double, but I assume I can't modify the value this way. I'm trying to format the result with a comma and two decimal places. Do I have convert the array index value to something else first? I've read about this exception, but I'm having trouble understanding why I'm getting it. Is it because I have two different data types or something? If I am I don't know about it and what to do about it. I'm specifying floating point.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It must be because the type coming out of the 'compensationArray' is not a Double. Because a Double value works fine in that format:


Output:


I'm trying to format the result with a comma and two decimal places.


That is not what the format you provided does. It uses the locale-specific grouping (comma for thousands, dot for decimals for me), makes the output 20 characters wide (because the width is 20), and shows 0 decimal places (because the precision is 0).
 
Marixa Garcia
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Luke wrote:It must be because the type coming out of the 'compensationArray' is not a Double. Because a Double value works fine in that format:


Output:


I'm trying to format the result with a comma and two decimal places.


That is not what the format you provided does. It uses the locale-specific grouping (comma for thousands, dot for decimals for me), makes the output 20 characters wide (because the width is 20), and shows 0 decimal places (because the precision is 0).



Thanks. Looks like more than one error I had. Funny I don't get the exception error anymore in NetBeans. (Haven't tried the command line yet.) I changed the "f" to "F" (grasping at straws), but changed it back and presto no exception! But I will fix the printf to do what I want.
reply
    Bookmark Topic Watch Topic
  • New Topic