Floating point nuisance

Blitz3D Forums/Blitz3D Programming/Floating point nuisance

Good news: You probably don't need to resolve anything. It's all as it should be.
Okay, first of all it ISNT good news. I save the values using WriteFloat and load them using ReadFloat. I use the loaded value to position the object - this of course means that it shifts to the right by roughly 2.4 units.

Clearly this is going to be a problem though if more values like this appear. I dont want to save the data as a string since it takes up more space and I'd like to minimise the file size.

Floyd: I have tried this and it doesn't give the results I expect. This demo below gives a return value of 189.979996

Function LimitFloat#( value#, decimal_places=5)
	
	decimal_point = Instr( value, "." )
	
	tmp$ = Left$(value, decimal_point ) + Mid$(value, decimal_point+1, decimal_places) + "0"
	value# = tmp
	Return value#

End Function

Print LimitFloat#(189.987654321, 2)

Unusual yes. Also damned annoying.