Issue
I am reading data from the robot's sensor. it gives this data as a list:
data:[1.0014142543, 0.4142543254, 4.5432544179]
I'd like to convert it like this format:
data:[1.00, 0.41, 4.54]
I am running it with python2.
I think this post for one number.
any ideas or suggestions, it would be highly appreciated.
Solution
Considering data as list ,
Using round :
>> data=[1.00, 0.41, 4.54]
>> [round(item,2) for item in data]
Using Float and Format:
>> [float(format(item,".2f")) for item in data]
Output :
[1.0, 0.41, 4.54]
Answered By - redhatvicky Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.