Forums > MaxMSP

Float comes with unexpected decimals

September 18, 2011 | 9:31 am


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


– Pasted Max Patch, click to expand. –

September 18, 2011 | 9:49 am

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

September 18, 2011 | 1:01 pm

well preset takes numbers as such …

September 18, 2011 | 3:07 pm

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 ?

September 18, 2011 | 8:20 pm

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

September 19, 2011 | 8:43 am

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…

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

– Pasted Max Patch, click to expand. –

September 19, 2011 | 1:24 pm

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

September 19, 2011 | 2:54 pm

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.

September 19, 2011 | 9:12 pm

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.

Viewing 9 posts - 1 through 9 (of 9 total)