Storing a positive floating point number in a known range in two bytes

I know that a number x lies between n and f (f > n > 0). So my idea is to bring that range to [0, 0.65535] by 0.65535 * (x – n) / (f – n). Then I just could multiply by 10000, round and store integer in two bytes. Is it going to… Read More Storing a positive floating point number in a known range in two bytes

How to display two decimal points in python, when a number is perfectly divisible?

Currently I am trying to solve a problem, where I am supposed to print the answer upto two decimal points without rounding off. I have used the below code for this purpose import math a=1.175 #value of a after some division print(math.floor(a*100)/100) The output we get is: 1.17 #Notice value which has two decimal points… Read More How to display two decimal points in python, when a number is perfectly divisible?