May-15-2021, 08:59 PM
Good day. I receive data from the device in the form: [1663] but it should be written as 166.3. Tell me how to do this?
Adding a comma in the resulting value
|
May-15-2021, 08:59 PM
Good day. I receive data from the device in the form: [1663] but it should be written as 166.3. Tell me how to do this?
May-15-2021, 10:29 PM
data_from_the_device = [1663] written_as = data_from_the_device[0] * 0.1 print(written_as)
May-16-2021, 02:14 AM
Is the data a number, a string, a bytearray, what?
May-16-2021, 04:19 AM
May-16-2021, 04:42 AM
use string formatting
print(f'{written_as:.1f}')or data_from_the_device = [1663] print(f'{data_from_the_device[0] * 0.1:.1f}')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
May-16-2021, 04:48 AM
(May-16-2021, 04:42 AM)buran Wrote: use string formatting Everything worked, thank you so much
May-22-2021, 09:24 PM
There was another problem. Now I want to write this data to the database. But how to write correctly:
Now I write like this: cursor.execute(sql, (newHireDate, result1[0] * 0.1, result2[0] * 0.1,result3[0] * 0.1,result4[0] * 0.1,result5[0] * 0.1,result6[0] * 0.1,))But in the database it is written as: 166.3 9.4 21.900000000000002 181.0 47.800000000000004 12.200000000000001 |
|