lkavo Registered User
#1

Does anyone know why this error is happening in my programme?

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'y'
at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at sovdev.main(sovdev.java:192)

Skrynesaver Registered User
#2

Does line 192 of sovdev.java contain a printf statement with an invalid format specifier?, perhaps "%y"

lkavo Registered User
#3

Nope all my .f are %s and changing theses to %S doesn't seem to make any difference

henryporter Registered User
#4

Maybe stick the code up here so we can have a look

1 person has thanked this post
Skrynesaver Registered User
#5

Have you tried adding a debug logging of the values you are attempting to convert?

lkavo Registered User
#6

if ((totalPrice >= 20.00) && (totalPrice < 40.00)) {

discountAmount = totalPrice*DISCOUNT1;

netPrice = totalPrice - discountAmount;

System.out.printf("You have recieved a discount value of %s",DISCOUNT1);
System.out.printf("% yielding you a discount of %s£",discountAmount);
System.out.printf("Your final cost after the discount has been applied is %s £" , netPrice);
}
else if (totalPrice >= 40.00) {

discountAmount = totalPrice*DISCOUNT2;

netPrice = totalPrice - discountAmount;

System.out.printf("You have recieved a discount value of %s",DISCOUNT1);
System.out.printf("% yielding you a discount of %s£",discountAmount);
System.out.printf("Your final cost after the discount has been applied is %s £" , netPrice);
}

else {
System.out.printf("Your total has come to % £", totalPrice);
}

and the error is

Exception in thread "main" 0.05java.util.UnknownFormatConversionException: Conversion = 'y'
at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at sovdev.main(sovdev.java:183)

Call Me Jimmy Registered User
#7

lkavo said:
if ((totalPrice >= 20.00) && (totalPrice < 40.00)) {

discountAmount = totalPrice*DISCOUNT1;

netPrice = totalPrice - discountAmount;

System.out.printf("You have recieved a discount value of %s",DISCOUNT1);
System.out.printf("% yielding you a discount of %s£",discountAmount);
System.out.printf("Your final cost after the discount has been applied is %s £" , netPrice);
}
else if (totalPrice >= 40.00) {

discountAmount = totalPrice*DISCOUNT2;

netPrice = totalPrice - discountAmount;

System.out.printf("You have recieved a discount value of %s",DISCOUNT1);
System.out.printf("% yielding you a discount of %s£",discountAmount);
System.out.printf("Your final cost after the discount has been applied is %s £" , netPrice);
}

else {
System.out.printf("Your total has come to % £", totalPrice);
}

and the error is

Exception in thread "main" 0.05java.util.UnknownFormatConversionException: Conversion = 'y'
at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at sovdev.main(sovdev.java:183)



Is it this line, you might have to add a symbol (backslash?) to allow the '%' to be printed? Like you're trying to print out the % to the screen but it might be misinterpreting as a formatting '%'...

EDIT: Actually not sure what you're doin with that first '%' on its own?

lkavo Registered User
#8

Still nothing.

Call Me Jimmy Registered User
#9

lkavo said:
Still nothing.


Well try removing that first percentage in that line and see if it compiles.

Skrynesaver Registered User
#10

or even use printf escaping "%%"

lkavo Registered User
#11

I got it working. Thanks for the help

1 person has thanked this post

Want to share your thoughts?

Login here to discuss!