I don't have the luxury of floating point precision and are very limited on code space / ram / speed etc.
TMP = 2562
DEG = str(int(TMP/100))+'.'+str(TMP % 100)
print(DEG)
>> 25.62
Is there a more pythionc way of achieving this formatting ?
I don't have the luxury of floating point precision and are very limited on code space / ram / speed etc.
TMP = 2562
DEG = str(int(TMP/100))+'.'+str(TMP % 100)
print(DEG)
>> 25.62
Is there a more pythionc way of achieving this formatting ?
Not sure if I understand the question correctly. But a more pythonic way to format the number to a .2 decimal string would be:
TMP = 2562
DEG = "{:.2f}".format(TMP/100)
print(DEG)
>> 25.62
Edit 2021: Or when using python3.6 or higher:
TMP = 2562
DEG = f"{TMP/100:.2f}"
print(DEG)
>> 25.62
TMP = 2562
float(TMP)/100
>>> 25.62
Does that answer your question? here's the reference : https://docs.micropython.org/en/latest/pyboard/reference/asm_thumb2_float.html#convert-between-integer-and-float