0

What means 0.2f in python

I have what does to 2f mean. I sometimes saw it in code, but I don't get it. Example: print("\nYour Celsius value is {:0.2f}ºC.\n".format(answer))

3rd Aug 2021, 4:21 PM
Gamer M
Gamer M - avatar
3 odpowiedzi
+ 4
Gamer M, Please specify a language name in the tags, one or some that specifically be relevant to the question. You are taking multiple courses, it's hard to deduce to narrow down the scope by language, and 'self self-learning' doesn't help here.
3rd Aug 2021, 4:40 PM
Ipang
+ 3
Now that you pasted your example, I can tell you definitively that it is meant to indicate a floating point value within your format brackets. However, 0.2 means that you are also formatting your output to two points of precision. In this case, only 2, so your format would look like this: 3.14 2.72 etc
3rd Aug 2021, 5:16 PM
BootInk
BootInk - avatar
+ 2
Well, it could mean any number of things. It could mean 2.0 floating point, as f denotes a floating point literal in most languages. It could also be 2f hexadecimal, which is equivalent to 47 decimal. It could also be a string literal too. Couldn't be a variable name, as most languages specify that numbers cannot be the first character of a variable name. Beyond that, no idea. Would have to see the specific code you're talking about to give you a certain answer. I would suggest linking your code playground or paste the code in your questions, otherwise you won't get good results from them.
3rd Aug 2021, 4:33 PM
BootInk
BootInk - avatar