Float comes with unexpected decimals

7391's icon

Hello

I do simple math on integers which becomes floats at a point in this very simple patch. Problem is that I have some very small decimals appearing and can't do what I want to do : create a message to external world (a light software) and recall presets in it with the float at the end. And you know that in this case 10.03 is not 10.02999999 AT ALL :)

Perhaps the preset obj adds a 'strange' integer ? Because It seems I have no prob with the recall of the first slot but only with the next.

I know about the Float Display Correction Option, but it do not changes my problem here apparently.

Thanks for any help

Max Patch
Copy patch and select New From Clipboard in Max.

Charles

seejayjames's icon

[sprintf] can take floats and reformat them with however many places you want, or you can try [round].

Roman Thilenius's icon

well preset takes numbers as such ...

7391's icon

Tanks but I've already tried round 0.01 and it seemed to me it did not work properly In this case. Can you tell me what is the syntax to round a float in sprintf ?

7391's icon

Ok ! the %.2f thing in sprintf obj seems to do the trick.
Thanks.

7391's icon

Crazy ! I was wrong : the message obj has the right text but if you print it you'll see that the 'wrong' float comes again ! It stays in memory…

Max Patch
Copy patch and select New From Clipboard in Max.

Does someone knows how to deal with floats in this case ?

spectro's icon

Max interprets the value you are creating as a floating point number and so, the "limited precision of floats issue", or whatever its proper name is - a problem not limited to this application alone BTW - rears its ugly head. (Do a search on this forum for "float representation" for example). It may be possible to resolve this, but it may end up being easier for you if you can revise the expected message formatting, for example in the form of two separate ints (or a seperator other than decimal point you can parse at the receiving end) rather than a float, ie: set/seq/X2LoadAndFireCue 40 6 or set/seq/X2LoadAndFireCue 40:06

7391's icon

Thanks a lot Spectro
I was afraid about such a thing. Unfortunately, the 'client' software is using floats to stock its own presets. I have no other solution than to send a float in the osc message. I'll try to find a trick.

7391's icon

Back and forth !
The last patch works indeed. If I send the message right away via udp, everything's ok. I was taken in by the print object which output the 'entire' float again.
Thanks