Float to S32 conversion
16 Jun 2012 22:33 #21018
by GStewart
Float to S32 conversion was created by GStewart
I was trying to convert a floating point number to a S32. I connected the encoder.0.position to the conv_float_s32 function, but it seems to truncate instead of round. For example, 6.997 converts to 6 instead of 7.
Is there a way to make conv_float_s32 round? Or is there a way to round the float before conversion?
Thanks
Glenn Stewart
Is there a way to make conv_float_s32 round? Or is there a way to round the float before conversion?
Thanks
Glenn Stewart
Please Log in or Create an account to join the conversation.
16 Jun 2012 22:37 #21020
by andypugh
Replied by andypugh on topic Re:Float to S32 conversion
GStewart wrote:
I think that the only way to do that would be to add 0.5 to the float before converting. (Which, incidentally, is the normal way to do it in code)Is there a way to make conv_float_s32 round? Or is there a way to round the float before conversion?
Please Log in or Create an account to join the conversation.
16 Jun 2012 22:48 #21023
by GStewart
Replied by GStewart on topic Re:Float to S32 conversion
Thanks, I will give that a try
Please Log in or Create an account to join the conversation.
17 Jun 2012 19:28 #21045
by jmelson
Replied by jmelson on topic Re:Float to S32 conversion
andypugh wrote:
Jon
You have to add +0.5 for a positive number and -0.5 for a negative number.GStewart wrote:
I think that the only way to do that would be to add 0.5 to the float before converting. (Which, incidentally, is the normal way to do it in code)Is there a way to make conv_float_s32 round? Or is there a way to round the float before conversion?
Jon
Please Log in or Create an account to join the conversation.
Time to create page: 0.135 seconds