• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.IllegalFormatConversionException  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!