codeomnitrix
codeomnitrix

Reputation: 4249

struct.unpack with precision after decimal points

I am reading data from a binary file, it contains floating point data of which I want only first 6 digits after decimal point but its printing a pretty long string.

self.dataArray.append(struct.unpack("f", buf)[0])

I tried with this

self.dataArray.append(struct.unpack(".6f", buf)[0])

But it didn't worked.

Thanks in advance

Upvotes: 0

Views: 1423

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 114038

a float isnt a string and a string isnt a float.

all a float is, is a number of bytes interpreted as both a whole number part and a fractional part

the_float = struct.unpack("f", buf)[0]

print "The Float String %0.6f"%(the_float)

Upvotes: 4

Related Questions