I am trying to print a line with a with a float formatter to 2 decimal points like this:
print "You have a discount of 20% and the final cost of the item is'%.2f' dollars." % price
But when I do I get this error:
ValueError: unsupported format character 'a' (0x61) at index 27
What does this mean and how can I prevent it from happening?
Sorry, something went wrong. Generally an unsupported format character means that the input that you are putting into (some function) needs to be read as a different encoding, typically the default is ascii and you might try utf-8. Sorry, something went wrong.
Another cause for unsupported file format is the storage issue. There are times when the memory is full, and this might cause the files not to be loaded (although this is a rare case). Sometimes having the file in the storage itself causes the file to be broken, resulting in the unsupported format. 3. Sudden shutdown of device
The problem is with % characters in your csv. 2) From the ENCODING menu, select CONVERT TO UTF 8. I've had this problem several times before and it is due to special characters which are supported via ISO encoding but not supported by UTF8 encoding (which Odoo supports).
Egnyte Cloud File Service. The limit is 245 bytes (or characters) per path component (e.g., a file or folder name) and 5000 bytes (or characters) for the entire path (including the filename). Microsoft Office imposes a 215 character limit on Office files.
The issue is your 20%
, Python is reading ...20% and...
as "% a" % price
and it doesn't recognize %a
as a format.
You can use 20%%
as @Anand points out, or you can use string .format()
:
>>> price = 29.99
>>> print "You have a discount of 20% and the final cost of the item is {:.2f} dollars.".format(price)
You have a discount of 20% and the final cost of the item is 29.99 dollars.
Here the :.2f
gives you 2 decimal places as with %.2f
.
I think the issue is with the single %
sign after 20
, python maybe thinking it is a format specifier.
Try this -
print "You have a discount of 20%% and the final cost of the item is'%.2f' dollars." % price
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With