Reducing the decimal points of numbers (3d coordinates) in a file; how to input data to e.g. Python

I have a file full of coordinates of the form:

37.68899917602539 58.07500076293945 57.79100036621094

The numbers don't always have the same number of decimal points. I need to reduce the decimal points of all the numbers (there are 128 rows of 3 numbers) to 2.

I have tried to do this using Python but keep encountering obstacles when trying to use simple scripts I've found online surrounding the conversion/interpretation of the file itself. I don't seem to be able to input the numbers in the file as floats, or list(s) thereof.

I don't really want someone to write something for me; I'd like to try to understand the principle behind what it is I need to do, as a beginner to the language. Any help would be greatly appreciated.

Try:

awk '{for (i=1;i<=NF;i++) $i=sprintf ("%.2f",$i)}1' file
1 Like

Thank you, that actually worked flawlessly. I think I can understand what's going on, as well.

Much appreciated.